diff options
| author | Tim Graham <timograham@gmail.com> | 2017-01-21 20:02:00 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-21 20:02:00 -0500 |
| commit | d170c63351944fd91b2206d10f89e7ff75b53b76 (patch) | |
| tree | e2be66471ab071fa0ce75097d66650b650c53853 /django | |
| parent | c22212220a7900173358a1f16179dcfc9e03de78 (diff) | |
Refs #23919 -- Removed misc references to Python 2.
Diffstat (limited to 'django')
| -rw-r--r-- | django/apps/config.py | 7 | ||||
| -rwxr-xr-x | django/conf/project_template/manage.py-tpl | 19 | ||||
| -rw-r--r-- | django/contrib/gis/measure.py | 9 | ||||
| -rw-r--r-- | django/core/checks/model_checks.py | 2 | ||||
| -rw-r--r-- | django/core/files/temp.py | 11 | ||||
| -rw-r--r-- | django/core/servers/basehttp.py | 1 | ||||
| -rw-r--r-- | django/db/backends/mysql/base.py | 1 | ||||
| -rw-r--r-- | django/db/backends/oracle/introspection.py | 2 | ||||
| -rw-r--r-- | django/db/migrations/serializer.py | 16 | ||||
| -rw-r--r-- | django/db/models/expressions.py | 6 | ||||
| -rw-r--r-- | django/db/models/query_utils.py | 5 | ||||
| -rw-r--r-- | django/db/models/sql/compiler.py | 10 | ||||
| -rw-r--r-- | django/forms/utils.py | 6 | ||||
| -rw-r--r-- | django/test/utils.py | 2 | ||||
| -rw-r--r-- | django/utils/deconstruct.py | 2 | ||||
| -rw-r--r-- | django/utils/html.py | 4 | ||||
| -rw-r--r-- | django/utils/html_parser.py | 4 | ||||
| -rw-r--r-- | django/utils/translation/trans_real.py | 9 |
18 files changed, 28 insertions, 88 deletions
diff --git a/django/apps/config.py b/django/apps/config.py index 78762dd612..1bc684b3ca 100644 --- a/django/apps/config.py +++ b/django/apps/config.py @@ -17,7 +17,7 @@ class AppConfig: self.name = app_name # Root module for the application eg. <module 'django.contrib.admin' - # from 'django/contrib/admin/__init__.pyc'>. + # from 'django/contrib/admin/__init__.py'>. self.module = app_module # Reference to the Apps registry that holds this AppConfig. Set by the @@ -37,13 +37,12 @@ class AppConfig: self.verbose_name = self.label.title() # Filesystem path to the application directory eg. - # u'/usr/lib/python2.7/dist-packages/django/contrib/admin'. Unicode on - # Python 2 and a str on Python 3. + # '/path/to/django/contrib/admin'. if not hasattr(self, 'path'): self.path = self._path_from_module(app_module) # Module containing models eg. <module 'django.contrib.admin.models' - # from 'django/contrib/admin/models.pyc'>. Set by import_models(). + # from 'django/contrib/admin/models.py'>. Set by import_models(). # None if the application doesn't have a models module. self.models_module = None diff --git a/django/conf/project_template/manage.py-tpl b/django/conf/project_template/manage.py-tpl index 41309844e0..9f83e65491 100755 --- a/django/conf/project_template/manage.py-tpl +++ b/django/conf/project_template/manage.py-tpl @@ -6,17 +6,10 @@ if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") try: from django.core.management import execute_from_command_line - except ImportError: - # The above import may fail for some other reason. Ensure that the - # issue is really that Django is missing to avoid masking other - # exceptions on Python 2. - try: - import django - except ImportError: - raise ImportError( - "Couldn't import Django. Are you sure it's installed and " - "available on your PYTHONPATH environment variable? Did you " - "forget to activate a virtual environment?" - ) - raise + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc execute_from_command_line(sys.argv) diff --git a/django/contrib/gis/measure.py b/django/contrib/gis/measure.py index fa3d7c34f2..d19737a118 100644 --- a/django/contrib/gis/measure.py +++ b/django/contrib/gis/measure.py @@ -159,9 +159,6 @@ class MeasureBase: else: raise TypeError('%(class)s must be divided with number or %(class)s' % {"class": pretty_name(self)}) - def __div__(self, other): # Python 2 compatibility - return type(self).__truediv__(self, other) - def __itruediv__(self, other): if isinstance(other, NUMERIC_TYPES): self.standard /= float(other) @@ -169,9 +166,6 @@ class MeasureBase: else: raise TypeError('%(class)s must be divided with number' % {"class": pretty_name(self)}) - def __idiv__(self, other): # Python 2 compatibility - return type(self).__itruediv__(self, other) - def __bool__(self): return bool(self.standard) @@ -333,9 +327,6 @@ class Area(MeasureBase): else: raise TypeError('%(class)s must be divided by a number' % {"class": pretty_name(self)}) - def __div__(self, other): # Python 2 compatibility - return type(self).__truediv__(self, other) - # Shortcuts D = Distance diff --git a/django/core/checks/model_checks.py b/django/core/checks/model_checks.py index a8b5652662..2397fe3bb2 100644 --- a/django/core/checks/model_checks.py +++ b/django/core/checks/model_checks.py @@ -64,7 +64,7 @@ def _check_lazy_references(apps, ignore=None): operation, args, keywords = obj, [], {} while hasattr(operation, 'func'): # The or clauses are redundant but work around a bug (#25945) in - # functools.partial in Python 3 <= 3.5.1 and Python 2 <= 2.7.11. + # functools.partial in Python <= 3.5.1. args.extend(getattr(operation, 'args', []) or []) keywords.update(getattr(operation, 'keywords', {}) or {}) operation = operation.func diff --git a/django/core/files/temp.py b/django/core/files/temp.py index f5aea1a9a8..d5c56a0ad0 100644 --- a/django/core/files/temp.py +++ b/django/core/files/temp.py @@ -9,8 +9,8 @@ if the same flag is not provided [1][2]. Note that this does not address the more general issue of opening a file for writing and reading in multiple processes in a manner that works across platforms. -Also note that the custom version of NamedTemporaryFile does not support the -full range of keyword arguments available in Python 2.6+ and 3.0+. +The custom version of NamedTemporaryFile doesn't support the same keyword +arguments available in tempfile.NamedTemporaryFile. 1: https://mail.python.org/pipermail/python-list/2005-December/336957.html 2: http://bugs.python.org/issue14243 @@ -30,10 +30,9 @@ if os.name == 'nt': Temporary file object constructor that supports reopening of the temporary file in Windows. - Note that unlike tempfile.NamedTemporaryFile from the standard library, - __init__() does not support the 'delete' keyword argument in - Python 2.6+, or the 'delete', 'buffering', 'encoding', or 'newline' - keyword arguments in Python 3.0+. + Unlike tempfile.NamedTemporaryFile from the standard library, + __init__() doesn't support the 'delete', 'buffering', 'encoding', or + 'newline' keyword arguments. """ def __init__(self, mode='w+b', bufsize=-1, suffix='', prefix='', dir=None): fd, name = tempfile.mkstemp(suffix=suffix, prefix=prefix, dir=dir) diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py index a9ab0668f7..5a551b8ab1 100644 --- a/django/core/servers/basehttp.py +++ b/django/core/servers/basehttp.py @@ -83,7 +83,6 @@ class WSGIServer(simple_server.WSGIServer): super(WSGIServer, self).handle_error(request, client_address) -# Inheriting from object required on Python 2. class ServerHandler(simple_server.ServerHandler): def handle_error(self): # Ignore broken pipe errors, otherwise pass on diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index d056392753..1b5dc864b0 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -2,7 +2,6 @@ MySQL database backend for Django. Requires mysqlclient: https://pypi.python.org/pypi/mysqlclient/ -MySQLdb is supported for Python 2 only: http://sourceforge.net/projects/mysql-python """ import re import sys diff --git a/django/db/backends/oracle/introspection.py b/django/db/backends/oracle/introspection.py index 7af2a18a8d..8a648dba3f 100644 --- a/django/db/backends/oracle/introspection.py +++ b/django/db/backends/oracle/introspection.py @@ -81,7 +81,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection): self.cache_bust_counter)) description = [] for desc in cursor.description: - name = force_text(desc[0]) # cx_Oracle always returns a 'str' on both Python 2 and 3 + name = force_text(desc[0]) # cx_Oracle always returns a 'str' internal_size, default = field_map[name] name = name % {} # cx_Oracle, for some reason, doubles percent signs. description.append(FieldInfo(*(name.lower(),) + desc[1:3] + (internal_size,) + desc[4:] + (default,))) diff --git a/django/db/migrations/serializer.py b/django/db/migrations/serializer.py index e15ffd87b5..58f90beaa2 100644 --- a/django/db/migrations/serializer.py +++ b/django/db/migrations/serializer.py @@ -160,24 +160,14 @@ class FunctionTypeSerializer(BaseSerializer): if "<" not in self.value.__qualname__: # Qualname can include <locals> return "%s.%s" % \ (self.value.__module__, self.value.__qualname__), {"import %s" % self.value.__module__} - # Python 2/fallback version + # Fallback version module_name = self.value.__module__ - # Make sure it's actually there and not an unbound method + # Make sure it's actually there module = import_module(module_name) if not hasattr(module, self.value.__name__): raise ValueError( - "Could not find function %s in %s.\n" - "Please note that due to Python 2 limitations, you cannot " - "serialize unbound method functions (e.g. a method " - "declared and used in the same class body). Please move " - "the function into the main module body to use migrations.\n" - "For more information, see " - "https://docs.djangoproject.com/en/%s/topics/migrations/#serializing-values" - % (self.value.__name__, module_name, get_docs_version()) + "Could not find function %s in %s.\n" % (self.value.__name__, module_name) ) - # Needed on Python 2 only - if module_name == '__builtin__': - return self.value.__name__, set() return "%s.%s" % (module_name, self.value.__name__), {"import %s" % module_name} diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index de60a160e0..a1cec2393a 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -60,9 +60,6 @@ class Combinable: def __truediv__(self, other): return self._combine(other, self.DIV, False) - def __div__(self, other): # Python 2 compatibility - return type(self).__truediv__(self, other) - def __mod__(self, other): return self._combine(other, self.MOD, False) @@ -103,9 +100,6 @@ class Combinable: def __rtruediv__(self, other): return self._combine(other, self.DIV, True) - def __rdiv__(self, other): # Python 2 compatibility - return type(self).__rtruediv__(self, other) - def __rmod__(self, other): return self._combine(other, self.MOD, True) diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index 54088b4fbb..c94a03f549 100644 --- a/django/db/models/query_utils.py +++ b/django/db/models/query_utils.py @@ -27,11 +27,8 @@ class InvalidQuery(Exception): def subclasses(cls): yield cls - # Python 2 lacks 'yield from', which could replace the inner loop for subclass in cls.__subclasses__(): - # yield from subclasses(subclass) - for item in subclasses(subclass): - yield item + yield from subclasses(subclass) class QueryWrapper: diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 1be406d704..5e5984dfb3 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -875,14 +875,8 @@ class SQLCompiler: try: cursor.execute(sql, params) except Exception: - try: - # Might fail for server-side cursors (e.g. connection closed) - cursor.close() - except Exception: - # Ignore clean up errors and raise the original error instead. - # Python 2 doesn't chain exceptions. Remove this error - # silencing when dropping Python 2 compatibility. - pass + # Might fail for server-side cursors (e.g. connection closed) + cursor.close() raise if result_type == CURSOR: diff --git a/django/forms/utils.py b/django/forms/utils.py index 59d70178f4..b23e6be0cc 100644 --- a/django/forms/utils.py +++ b/django/forms/utils.py @@ -1,5 +1,6 @@ import json import sys +from collections import UserList from django.conf import settings from django.core.exceptions import ValidationError # backwards compatibility @@ -8,11 +9,6 @@ from django.utils.encoding import force_text from django.utils.html import escape, format_html, format_html_join, html_safe from django.utils.translation import ugettext_lazy as _ -try: - from collections import UserList -except ImportError: # Python 2 - from UserList import UserList - def pretty_name(name): """Converts 'first_name' to 'First name'""" diff --git a/django/test/utils.py b/django/test/utils.py index 2bd6bb4d0f..ef837ce5c7 100644 --- a/django/test/utils.py +++ b/django/test/utils.py @@ -310,7 +310,7 @@ def get_runner(settings, test_runner_class=None): test_runner_class = settings.TEST_RUNNER test_path = test_runner_class.split('.') - # Allow for Python 2.5 relative paths + # Allow for relative paths if len(test_path) > 1: test_module_name = '.'.join(test_path[:-1]) else: diff --git a/django/utils/deconstruct.py b/django/utils/deconstruct.py index 848b939b40..6bc70f7e53 100644 --- a/django/utils/deconstruct.py +++ b/django/utils/deconstruct.py @@ -24,7 +24,7 @@ def deconstructible(*args, **kwargs): Returns a 3-tuple of class import path, positional arguments, and keyword arguments. """ - # Python 2/fallback version + # Fallback version if path: module_name, _, name = path.rpartition('.') else: diff --git a/django/utils/html.py b/django/utils/html.py index fb9c18219c..f7f9a63350 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -172,9 +172,7 @@ def strip_tags(value): while '<' in value and '>' in value: new_value = _strip_once(value) if len(new_value) >= len(value): - # _strip_once was not able to detect more tags or length increased - # due to http://bugs.python.org/issue20288 - # (affects Python 2 < 2.7.7 and Python 3 < 3.3.5) + # _strip_once was not able to detect more tags break value = new_value return value diff --git a/django/utils/html_parser.py b/django/utils/html_parser.py index e3e19ee9c3..6b46ddc368 100644 --- a/django/utils/html_parser.py +++ b/django/utils/html_parser.py @@ -11,9 +11,7 @@ except AttributeError: class HTMLParser(html.parser.HTMLParser): """Explicitly set convert_charrefs to be False. - This silences a deprecation warning on Python 3.4, but we can't do - it at call time because Python 2.7 does not have the keyword - argument. + This silences a deprecation warning on Python 3.4. """ def __init__(self, convert_charrefs=False, **kwargs): html.parser.HTMLParser.__init__(self, convert_charrefs=convert_charrefs, **kwargs) diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index 62ff122621..c8913feb71 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -101,7 +101,6 @@ class DjangoTranslation(gettext_module.GNUTranslations): gettext_module.GNUTranslations.__init__(self) if domain is not None: self.domain = domain - self.set_output_charset('utf-8') # For Python 2 gettext() (#25720) self.__language = language self.__to_language = to_language(language) @@ -326,11 +325,7 @@ def do_translate(message, translation_function): def gettext(message): - """ - Returns a string of the translation of the message. - - Returns a string on Python 3 and an UTF-8-encoded bytestring on Python 2. - """ + """Return a string of the translation of the message.""" return do_translate(message, 'gettext') @@ -372,8 +367,6 @@ def ngettext(singular, plural, number): """ Returns a string of the translation of either the singular or plural, based on the number. - - Returns a string on Python 3 and an UTF-8-encoded bytestring on Python 2. """ return do_ntranslate(singular, plural, number, 'ngettext') |
