mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Refs #23919 -- Removed misc references to Python 2.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,)))
|
||||
|
||||
@@ -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}
|
||||
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user