Automatically upgrade your Django projects.
Reason this release was yanked:
faultily lists python 3.6 to 3.7 compatibility
Project description
Automatically upgrade your Django projects.
Installation
Use pip:
python -m pip install django-upgrade
Python 3.6 to 3.9 supported.
Or with pre-commit in the repos section of your .pre-commit-config.yaml file:
- repo: https://github.com/adamchainz/django-upgrade
rev: '' # replace with latest tag on GitHub
hooks:
- id: django-upgrade
Are your tests slow? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.
Currently an experimental alternative to django-codemod, whose underlying library LibCST is relatively slow.
Usage
Run django-upgrade --help on the commandline for information.
Fixers
Django 2.2
Based on the Django 2.2 release notes.
django.core.paginator
QuerySetPaginator → Paginator
-from django.core.paginator import QuerySetPaginator
+from django.core.paginator import Paginator
-QuerySetPaginator(...)
+Paginator(...)
django.utils.timezone
FixedOffset(x, y) → timezone(timedelta(minutes=x), y)
Will leave code broken with an ImportError if FixedOffset is called with (only) *args or **kwargs.
-from django.utils.timezone import FixedOffset
-FixedOffset(120, "Super time")
+from datetime import timedelta, timezone
+timezone(timedelta(minutes=120), "Super time")
Django 3.0
Based on the Django 3.0 release notes.
django.utils.encoding
smart_text() → smart_str() , force_text() → force_str()
django-upgrade does not support Python 2 so these names are always replaced.
-from django.utils.encoding import force_text, smart_text
+from django.utils.encoding import force_str, smart_str
-force_text("yada")
-smart_text("yada")
+force_str("yada")
+smart_str("yada")
Django 3.1
Based on the Django 3.1 release notes.
PASSWORD_RESET_TIMEOUT_DAYS
Rewrites the setting PASSWORD_RESET_TIMEOUT_DAYS → PASSWORD_RESET_TIMEOUT, including multiplication by the number of seconds in a day.
Settings files are heuristically detected as modules with the word “settings” somewhere in their path.
-PASSWORD_RESET_TIMEOUT_DAYS = 4
+PASSWORD_RESET_TIMEOUT = 60 * 60 * 24 * 4
Django 3.2
Based on the Django 3.2 release notes.
django.core.validators.EmailValidator
Rewrites keyword arguments whitelist → allowlist and domain_whitelist → domain_allowlist.
from django.core.validators import EmailValidator
-EmailValidator(whitelist=["example.com"])
+EmailValidator(allowlist=["example.com"])
-EmailValidator(domain_whitelist=["example.org"])
+EmailValidator(domain_allowlist=["example.org"])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_upgrade-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c307513c2c514734a1bd84a3b6d944435feeee5d7ecdcf349d1e4edea8afc26b |
|
MD5 | b1ab8c7c2ec824bb76f40a0abe4d73f4 |
|
BLAKE2b-256 | 013503e1b2edc33d8a0938af297a32853a1b7cface42f980d10881d70b2f5b77 |