diff options
| author | Tim Graham <timograham@gmail.com> | 2017-01-25 13:59:25 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-25 13:59:25 -0500 |
| commit | 1c466994d9729a8902d34e277a3a685bef2a08e1 (patch) | |
| tree | 3a0c5ea4fc352aead66378f1fc2217feb6e1e2c7 /django | |
| parent | 11856ea44e4dd1ff2358c559c0d04ac848832c23 (diff) | |
Refs #23919 -- Removed misc Python 2/3 references.
Diffstat (limited to 'django')
| -rw-r--r-- | django/apps/config.py | 4 | ||||
| -rw-r--r-- | django/contrib/auth/hashers.py | 3 | ||||
| -rw-r--r-- | django/contrib/auth/views.py | 4 | ||||
| -rw-r--r-- | django/core/mail/message.py | 4 | ||||
| -rw-r--r-- | django/core/management/commands/shell.py | 2 | ||||
| -rw-r--r-- | django/db/backends/oracle/base.py | 3 | ||||
| -rw-r--r-- | django/db/migrations/serializer.py | 22 | ||||
| -rw-r--r-- | django/test/runner.py | 3 |
8 files changed, 18 insertions, 27 deletions
diff --git a/django/apps/config.py b/django/apps/config.py index 1bc684b3ca..4845557051 100644 --- a/django/apps/config.py +++ b/django/apps/config.py @@ -57,8 +57,8 @@ class AppConfig: """Attempt to determine app's filesystem path from its module.""" # See #21874 for extended discussion of the behavior of this method in # various cases. - # Convert paths to list because Python 3's _NamespacePath does not - # support indexing. + # Convert paths to list because Python's _NamespacePath doesn't support + # indexing. paths = list(getattr(module, '__path__', [])) if len(paths) != 1: filename = getattr(module, '__file__', None) diff --git a/django/contrib/auth/hashers.py b/django/contrib/auth/hashers.py index c52f31db59..49b4fa5b14 100644 --- a/django/contrib/auth/hashers.py +++ b/django/contrib/auth/hashers.py @@ -419,8 +419,7 @@ class BCryptSHA256PasswordHasher(BasePasswordHasher): # Hash the password prior to using bcrypt to prevent password # truncation as described in #20138. if self.digest is not None: - # Use binascii.hexlify() because a hex encoded bytestring is - # Unicode on Python 3. + # Use binascii.hexlify() because a hex encoded bytestring is str. password = binascii.hexlify(self.digest(force_bytes(password)).digest()) else: password = force_bytes(password) diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py index 6208b5fe41..c0e102234d 100644 --- a/django/contrib/auth/views.py +++ b/django/contrib/auth/views.py @@ -298,7 +298,7 @@ def password_reset_confirm(request, uidb64=None, token=None, else: post_reset_redirect = resolve_url(post_reset_redirect) try: - # urlsafe_base64_decode() decodes to bytestring on Python 3 + # urlsafe_base64_decode() decodes to bytestring uid = force_text(urlsafe_base64_decode(uidb64)) user = UserModel._default_manager.get(pk=uid) except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist): @@ -442,7 +442,7 @@ class PasswordResetConfirmView(PasswordContextMixin, FormView): def get_user(self, uidb64): try: - # urlsafe_base64_decode() decodes to bytestring on Python 3 + # urlsafe_base64_decode() decodes to bytestring uid = force_text(urlsafe_base64_decode(uidb64)) user = UserModel._default_manager.get(pk=uid) except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist): diff --git a/django/core/mail/message.py b/django/core/mail/message.py index f4f3eb1352..ae2e017b6e 100644 --- a/django/core/mail/message.py +++ b/django/core/mail/message.py @@ -324,8 +324,8 @@ class EmailMessage: try: content = content.decode('utf-8') except UnicodeDecodeError: - # If mimetype suggests the file is text but it's actually - # binary, read() will raise a UnicodeDecodeError on Python 3. + # If mimetype suggests the file is text but it's + # actually binary, read() raises a UnicodeDecodeError. mimetype = DEFAULT_ATTACHMENT_MIME_TYPE self.attachments.append((filename, content, mimetype)) diff --git a/django/core/management/commands/shell.py b/django/core/management/commands/shell.py index ce4d9daa7e..4b91c1b977 100644 --- a/django/core/management/commands/shell.py +++ b/django/core/management/commands/shell.py @@ -53,7 +53,7 @@ class Command(BaseCommand): import rlcompleter readline.set_completer(rlcompleter.Completer(imported_objects).complete) # Enable tab completion on systems using libedit (e.g. Mac OSX). - # These lines are copied from Lib/site.py on Python 3.4. + # These lines are copied from Python's Lib/site.py. readline_doc = getattr(readline, '__doc__', '') if readline_doc is not None and 'libedit' in readline_doc: readline.parse_and_bind("bind ^I rl_complete") diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 0cc21b639b..d19f189358 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -322,8 +322,7 @@ class OracleParam: param = Oracle_datetime.from_datetime(param) string_size = 0 - # Oracle doesn't recognize True and False correctly in Python 3. - # The conversion done below works both in 2 and 3. + # Oracle doesn't recognize True and False correctly. if param is True: param = 1 elif param is False: diff --git a/django/db/migrations/serializer.py b/django/db/migrations/serializer.py index fac8e4c189..f56b505381 100644 --- a/django/db/migrations/serializer.py +++ b/django/db/migrations/serializer.py @@ -8,7 +8,6 @@ import math import re import types import uuid -from importlib import import_module from django.db import models from django.db.migrations.operations.base import Operation @@ -155,20 +154,15 @@ class FunctionTypeSerializer(BaseSerializer): raise ValueError("Cannot serialize function: lambda") if self.value.__module__ is None: raise ValueError("Cannot serialize function %r: No module" % self.value) - # Python 3 is a lot easier, and only uses this branch if it's not local. - if getattr(self.value, "__qualname__", None) and getattr(self.value, "__module__", None): - if "<" not in self.value.__qualname__: # Qualname can include <locals> - return "%s.%s" % \ - (self.value.__module__, self.value.__qualname__), {"import %s" % self.value.__module__} - # Fallback version + module_name = self.value.__module__ - # 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" % (self.value.__name__, module_name) - ) - return "%s.%s" % (module_name, self.value.__name__), {"import %s" % module_name} + + if '<' not in self.value.__qualname__: # Qualname can include <locals> + return '%s.%s' % (module_name, self.value.__qualname__), {'import %s' % self.value.__module__} + + raise ValueError( + 'Could not find function %s in %s.\n' % (self.value.__name__, module_name) + ) class FunctoolsPartialSerializer(BaseSerializer): diff --git a/django/test/runner.py b/django/test/runner.py index 38578e7e0c..cb1893c56a 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -258,8 +258,7 @@ def default_test_processes(): """ # The current implementation of the parallel test runner requires # multiprocessing to start subprocesses with fork(). - # On Python 3.4+: if multiprocessing.get_start_method() != 'fork': - if not hasattr(os, 'fork'): + if multiprocessing.get_start_method() != 'fork': return 1 try: return int(os.environ['DJANGO_TEST_PROCESSES']) |
