This gist documents the steps that were taken to drop Python 2 support in Django User Accounts, an app in the Pinax project.
It is for most of the part similar to this other gist, which documents the steps that were taken to drop support in Pinax Ratings, another app in the Pinax project.
-
Remove Python 2 from test matrix
-
Remove redundant future statements/features
print_functonandunicode_literalsin this case, as they are enabled in Python 3 by default. -
Drop compatibility handling in
account.compat-
The
django.core.urlresolversmodule was moved todjango.urlsin version 1.10, and deprecated in version 2.0The lowest version of Django in this app is 1.11, so we can safely use functions from the latter module.
-
Also, as of Django 1.10,
user.is_authenticatedis a property, and not a method.We can therefore safely drop that part of the compatibility handling, too.
-
-
Drop
account.compataccount.compat.NoReverseMatch==>django.urls.NoReverseMatchaccount.compat.resolve==>django.urls.resolveaccount.compat.reverse==>django.urls.reverseaccount.compat.is_authenticated(user)==>user.is_authenticated
-
Drop unicode compatibility handlers
-
Drop
django.utils.sixdjango.utils.six.moves.reduce==>functools.reducedjango.utils.six.StringIO==>io.StringIOdjango.utils.six.moves.urllib.parse.urlparse==>urllib.parse.urlparse
-
Drop compatibility handlers for stdlib modules
collections.OrderedDictexists across all supported versions of Pythonurlparse.urlparse==>urllib.parse.urlparseurlparse.urlunparse==>urllib.parse.urlunparse
-
Prefer
settings.MIDDLEWAREtosettings.MIDDLEWARE_CLASSES- The
MIDDLEWARE_CLASSESsetting was deprecated in Django 1.10 and theMIDDLEWAREsetting took precedence. - Support for the old-style
MIDDLEWARE_CLASSESsetting was dropped in Django 2.0
- The
-
Update setup and docs
-
Fix issues identified by deepsource
-
PERFORMAMCE issue in
account/models.py1 occurence of inheriting from
object -
ANTI-PATTERN in
account/templatetags/account_tags.py1 occurrence of using
lenwithout comparison to determine if a sequence is emptyif len(bits): ...
Was changed to:
if len(bits) > 0: ...
-
BUG RISK in
account/auth_backends.pyMatch parameters in overriding methods with those in the respective overriden methods
def authenticate(self, *args, **credentials): ...
Was changed to
def authenticate(self, request, username=None, password=None, **kwargs): ...
Also, the body of the function was updated accordingly.
-
ANTI-PATTERN in
account/models.pyDrop occurrences of re-defining variables from outer scope.
def now(self): now = datetime.datetime.utcnow().replace(tzinfo=pytz.timezone("UTC")) timezone = settings.TIME_ZONE if not self.timezone else self.timezone return now.astimezone(pytz.timezone(timezone))
Was updated to
def now(self): now = datetime.datetime.utcnow().replace(tzinfo=pytz.timezone("UTC")) tz = settings.TIME_ZONE if not self.timezone else self.timezone return now.astimezone(pytz.timezone(tz))
In order to avoid shadowing the Python
timezonelibrary which was imported at the top-level
-
ALERT!: Deepsource also identified four style issues which I couldn't wrap my head around 😓.
TO-DO: Update Circle CI config file