From b9d12f1df7ac2bd596ef80a3dc040404e140f18f Mon Sep 17 00:00:00 2001 From: Nick Martini Date: Fri, 7 Sep 2012 16:05:12 -0400 Subject: [PATCH] setting stacklevel to 2 for all DeprecationWarning, tickets #18780, #18127 --- django/conf/__init__.py | 4 ++-- django/conf/urls/defaults.py | 2 +- django/contrib/admin/templatetags/adminmedia.py | 2 +- django/contrib/databrowse/__init__.py | 2 +- django/contrib/formtools/wizard/legacy.py | 2 +- django/contrib/localflavor/uk/forms.py | 2 +- django/contrib/localflavor/uk/uk_regions.py | 2 +- django/core/management/__init__.py | 4 ++-- django/middleware/common.py | 4 ++-- django/template/defaultfilters.py | 2 +- django/utils/copycompat.py | 2 +- django/utils/hashcompat.py | 2 +- django/utils/itercompat.py | 4 ++-- django/utils/text.py | 4 ++-- django/utils/unittest/case.py | 4 ++-- django/views/decorators/csrf.py | 4 ++-- 16 files changed, 23 insertions(+), 23 deletions(-) diff --git a/django/conf/__init__.py b/django/conf/__init__.py index f4d17ca9f3a0b..b6dc055df03ca 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -73,7 +73,7 @@ def __setattr__(self, name, value): raise ImproperlyConfigured("If set, %s must end with a slash" % name) elif name == "ADMIN_MEDIA_PREFIX": warnings.warn("The ADMIN_MEDIA_PREFIX setting has been removed; " - "use STATIC_URL instead.", DeprecationWarning) + "use STATIC_URL instead.", DeprecationWarning, stacklevel=2) elif name == "ALLOWED_INCLUDE_ROOTS" and isinstance(value, six.string_types): raise ValueError("The ALLOWED_INCLUDE_ROOTS setting must be set " "to a tuple, not a string.") @@ -193,7 +193,7 @@ def compat_patch_logging_config(logging_config): "handler: adding implicit debug-false-only filter. " "See http://docs.djangoproject.com/en/dev/releases/1.4/" "#request-exceptions-are-now-always-logged", - DeprecationWarning) + DeprecationWarning, stacklevel=2) filter_name = "require_debug_false" diff --git a/django/conf/urls/defaults.py b/django/conf/urls/defaults.py index 7d5c738bad43f..3596bf986f53c 100644 --- a/django/conf/urls/defaults.py +++ b/django/conf/urls/defaults.py @@ -1,6 +1,6 @@ import warnings warnings.warn("django.conf.urls.defaults is deprecated; use django.conf.urls instead", - DeprecationWarning) + DeprecationWarning, stacklevel=2) from django.conf.urls import (handler403, handler404, handler500, include, patterns, url) diff --git a/django/contrib/admin/templatetags/adminmedia.py b/django/contrib/admin/templatetags/adminmedia.py index b08d13c18fbd6..ee0cc91658983 100644 --- a/django/contrib/admin/templatetags/adminmedia.py +++ b/django/contrib/admin/templatetags/adminmedia.py @@ -11,5 +11,5 @@ def admin_media_prefix(): """ warnings.warn( "The admin_media_prefix template tag is deprecated. " - "Use the static template tag instead.", DeprecationWarning) + "Use the static template tag instead.", DeprecationWarning, stacklevel=2) return PrefixNode.handle_simple("ADMIN_MEDIA_PREFIX") diff --git a/django/contrib/databrowse/__init__.py b/django/contrib/databrowse/__init__.py index acb7626c8dbc6..7775cf611e375 100644 --- a/django/contrib/databrowse/__init__.py +++ b/django/contrib/databrowse/__init__.py @@ -2,4 +2,4 @@ from django.contrib.databrowse.sites import DatabrowsePlugin, ModelDatabrowse, DatabrowseSite, site -warnings.warn("The Databrowse contrib app is deprecated", DeprecationWarning) +warnings.warn("The Databrowse contrib app is deprecated", DeprecationWarning, stacklevel=2) diff --git a/django/contrib/formtools/wizard/legacy.py b/django/contrib/formtools/wizard/legacy.py index d07e959de07b4..cba3d5b1ede23 100644 --- a/django/contrib/formtools/wizard/legacy.py +++ b/django/contrib/formtools/wizard/legacy.py @@ -39,7 +39,7 @@ def __init__(self, form_list, initial=None): warnings.warn( 'Old-style form wizards have been deprecated; use the class-based ' 'views in django.contrib.formtools.wizard.views instead.', - DeprecationWarning) + DeprecationWarning, stacklevel=2) def __repr__(self): return "step: %d\nform_list: %s\ninitial_data: %s" % (self.step, self.form_list, self.initial) diff --git a/django/contrib/localflavor/uk/forms.py b/django/contrib/localflavor/uk/forms.py index 14624bc15fe39..f8d8b1c248abf 100644 --- a/django/contrib/localflavor/uk/forms.py +++ b/django/contrib/localflavor/uk/forms.py @@ -3,7 +3,7 @@ import warnings warnings.warn( 'The "UK" prefix for United Kingdom has been deprecated in favour of the ' - 'GB code. Please use the new GB-prefixed names.', DeprecationWarning) + 'GB code. Please use the new GB-prefixed names.', DeprecationWarning, stacklevel=2) UKPostcodeField = forms.GBPostcodeField UKCountySelect = forms.GBCountySelect diff --git a/django/contrib/localflavor/uk/uk_regions.py b/django/contrib/localflavor/uk/uk_regions.py index 5af19967c718e..0fd0907e35ab4 100644 --- a/django/contrib/localflavor/uk/uk_regions.py +++ b/django/contrib/localflavor/uk/uk_regions.py @@ -6,7 +6,7 @@ import warnings warnings.warn( 'The "UK" prefix for United Kingdom has been deprecated in favour of the ' - 'GB code. Please use the new GB-prefixed names.', DeprecationWarning) + 'GB code. Please use the new GB-prefixed names.', DeprecationWarning, stacklevel=2) UK_NATIONS_CHOICES = GB_NATIONS_CHOICES UK_REGION_CHOICES = GB_REGION_CHOICES diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index 98f75e0310ca1..38c68470c798e 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -401,7 +401,7 @@ def setup_environ(settings_mod, original_settings_path=None): "you likely need to update your 'manage.py'; " "please see the Django 1.4 release notes " "(https://docs.djangoproject.com/en/dev/releases/1.4/).", - DeprecationWarning) + DeprecationWarning, stacklevel=2) # Add this project to sys.path so that it's importable in the conventional # way. For example, if this file (manage.py) lives in a directory @@ -457,7 +457,7 @@ def execute_manager(settings_mod, argv=None): "you likely need to update your 'manage.py'; " "please see the Django 1.4 release notes " "(https://docs.djangoproject.com/en/dev/releases/1.4/).", - DeprecationWarning) + DeprecationWarning, stacklevel=2) setup_environ(settings_mod) utility = ManagementUtility(argv) diff --git a/django/middleware/common.py b/django/middleware/common.py index bb24977ce8649..98de7e40bd263 100644 --- a/django/middleware/common.py +++ b/django/middleware/common.py @@ -130,14 +130,14 @@ def _is_ignorable_404(uri): if getattr(settings, 'IGNORABLE_404_STARTS', ()): import warnings warnings.warn('The IGNORABLE_404_STARTS setting has been deprecated ' - 'in favor of IGNORABLE_404_URLS.', DeprecationWarning) + 'in favor of IGNORABLE_404_URLS.', DeprecationWarning, stacklevel=2) for start in settings.IGNORABLE_404_STARTS: if uri.startswith(start): return True if getattr(settings, 'IGNORABLE_404_ENDS', ()): import warnings warnings.warn('The IGNORABLE_404_ENDS setting has been deprecated ' - 'in favor of IGNORABLE_404_URLS.', DeprecationWarning) + 'in favor of IGNORABLE_404_URLS.', DeprecationWarning, stacklevel=2) for end in settings.IGNORABLE_404_ENDS: if uri.endswith(end): return True diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 1bfb6270239e9..03009da859219 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -55,7 +55,7 @@ def _dec(*args, **kwargs): warnings.warn("Setting the %s attribute of a template filter " "function is deprecated; use @register.filter(%s=%s) " "instead" % (attr, attr, getattr(func, attr)), - DeprecationWarning) + DeprecationWarning, stacklevel=2) setattr(_dec, attr, getattr(func, attr)) return wraps(func)(_dec) diff --git a/django/utils/copycompat.py b/django/utils/copycompat.py index 6ccf6c3ae5477..50c52e589cc7e 100644 --- a/django/utils/copycompat.py +++ b/django/utils/copycompat.py @@ -7,7 +7,7 @@ import warnings warnings.warn("django.utils.copycompat is deprecated; use the native copy module instead", - DeprecationWarning) + DeprecationWarning, stacklevel=2) # Monkeypatch copy's deepcopy registry to handle functions correctly. if (hasattr(copy, '_deepcopy_dispatch') and types.FunctionType not in copy._deepcopy_dispatch): diff --git a/django/utils/hashcompat.py b/django/utils/hashcompat.py index 62b1dfd12bd77..f2ac30898d763 100644 --- a/django/utils/hashcompat.py +++ b/django/utils/hashcompat.py @@ -6,7 +6,7 @@ import warnings warnings.warn("django.utils.hashcompat is deprecated; use hashlib instead", - DeprecationWarning) + DeprecationWarning, stacklevel=2) import hashlib md5_constructor = hashlib.md5 diff --git a/django/utils/itercompat.py b/django/utils/itercompat.py index aa329c152eb6f..5ca6ec08e3013 100644 --- a/django/utils/itercompat.py +++ b/django/utils/itercompat.py @@ -24,10 +24,10 @@ def product(*args, **kwds): def all(iterable): warnings.warn("django.utils.itercompat.all is deprecated; use the native version instead", - DeprecationWarning) + DeprecationWarning, stacklevel=2) return builtins.all(iterable) def any(iterable): warnings.warn("django.utils.itercompat.any is deprecated; use the native version instead", - DeprecationWarning) + DeprecationWarning, stacklevel=2) return builtins.any(iterable) diff --git a/django/utils/text.py b/django/utils/text.py index c19708458bc2c..163719579dcb5 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -211,14 +211,14 @@ def _html_words(self, length, truncate): def truncate_words(s, num, end_text='...'): warnings.warn('This function has been deprecated. Use the Truncator class ' - 'in django.utils.text instead.', category=DeprecationWarning) + 'in django.utils.text instead.', category=DeprecationWarning, stacklevel=2) truncate = end_text and ' %s' % end_text or '' return Truncator(s).words(num, truncate=truncate) truncate_words = allow_lazy(truncate_words, six.text_type) def truncate_html_words(s, num, end_text='...'): warnings.warn('This function has been deprecated. Use the Truncator class ' - 'in django.utils.text instead.', category=DeprecationWarning) + 'in django.utils.text instead.', category=DeprecationWarning, stacklevel=2) truncate = end_text and ' %s' % end_text or '' return Truncator(s).words(num, truncate=truncate, html=True) truncate_html_words = allow_lazy(truncate_html_words, six.text_type) diff --git a/django/utils/unittest/case.py b/django/utils/unittest/case.py index f906a4cb686a7..f9c7716e166fe 100644 --- a/django/utils/unittest/case.py +++ b/django/utils/unittest/case.py @@ -339,7 +339,7 @@ def run(self, result=None): addExpectedFailure(self, e.exc_info) else: warnings.warn("Use of a TestResult without an addExpectedFailure method is deprecated", - DeprecationWarning) + DeprecationWarning, stacklevel=2) result.addSuccess(self) except _UnexpectedSuccess: addUnexpectedSuccess = getattr(result, 'addUnexpectedSuccess', None) @@ -347,7 +347,7 @@ def run(self, result=None): addUnexpectedSuccess(self) else: warnings.warn("Use of a TestResult without an addUnexpectedSuccess method is deprecated", - DeprecationWarning) + DeprecationWarning, stacklevel=2) result.addFailure(self, sys.exc_info()) except SkipTest, e: self._addSkip(result, str(e)) diff --git a/django/views/decorators/csrf.py b/django/views/decorators/csrf.py index 60664ff9329a6..0516ee2257a9d 100644 --- a/django/views/decorators/csrf.py +++ b/django/views/decorators/csrf.py @@ -55,7 +55,7 @@ def csrf_response_exempt(view_func): """ warnings.warn("csrf_response_exempt is deprecated. It no longer performs a " "function, and calls to it can be removed.", - DeprecationWarning) + DeprecationWarning, stacklevel=2) return view_func def csrf_view_exempt(view_func): @@ -63,7 +63,7 @@ def csrf_view_exempt(view_func): Marks a view function as being exempt from CSRF view protection. """ warnings.warn("csrf_view_exempt is deprecated. Use csrf_exempt instead.", - DeprecationWarning) + DeprecationWarning, stacklevel=2) return csrf_exempt(view_func) def csrf_exempt(view_func):