Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adamchainz/django-upgrade
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.20.0
Choose a base ref
...
head repository: adamchainz/django-upgrade
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.22.1
Choose a head ref

Commits on Jul 23, 2024

  1. [pre-commit.ci] pre-commit autoupdate (#474)

    <!--pre-commit.ci start-->
    updates:
    - [github.com/pre-commit/mirrors-mypy: v1.10.1 →
    v1.11.0](pre-commit/mirrors-mypy@v1.10.1...v1.11.0)
    <!--pre-commit.ci end-->
    
    ---------
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Adam Johnson <me@adamj.eu>
    pre-commit-ci[bot] and adamchainz authored Jul 23, 2024
    Copy the full SHA
    a2dc761 View commit details

Commits on Jul 30, 2024

  1. [pre-commit.ci] pre-commit autoupdate (#475)

    <!--pre-commit.ci start-->
    updates:
    - [github.com/asottile/pyupgrade: v3.16.0 →
    v3.17.0](asottile/pyupgrade@v3.16.0...v3.17.0)
    <!--pre-commit.ci end-->
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    pre-commit-ci[bot] authored Jul 30, 2024
    Copy the full SHA
    dcc9aae View commit details

Commits on Aug 6, 2024

  1. [pre-commit.ci] pre-commit autoupdate (#476)

    <!--pre-commit.ci start-->
    updates:
    - [github.com/tox-dev/pyproject-fmt: 2.1.4 →
    2.2.1](tox-dev/pyproject-fmt@2.1.4...2.2.1)
    - [github.com/PyCQA/flake8: 7.1.0 →
    7.1.1](PyCQA/flake8@7.1.0...7.1.1)
    - [github.com/pre-commit/mirrors-mypy: v1.11.0 →
    v1.11.1](pre-commit/mirrors-mypy@v1.11.0...v1.11.1)
    <!--pre-commit.ci end-->
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    pre-commit-ci[bot] authored Aug 6, 2024
    Copy the full SHA
    989d5d3 View commit details
  2. Copy the full SHA
    d81f7d8 View commit details

Commits on Aug 10, 2024

  1. Move test requirement files into tests/ (#479)

    Makes the project a little bit tidier.
    adamchainz authored Aug 10, 2024
    Copy the full SHA
    e7048a3 View commit details
  2. Copy the full SHA
    fcb83ad View commit details

Commits on Aug 13, 2024

  1. [pre-commit.ci] pre-commit autoupdate (#481)

    <!--pre-commit.ci start-->
    updates:
    - [github.com/psf/black-pre-commit-mirror: 24.4.2 →
    24.8.0](psf/black-pre-commit-mirror@24.4.2...24.8.0)
    <!--pre-commit.ci end-->
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    pre-commit-ci[bot] authored Aug 13, 2024
    Copy the full SHA
    2d7d4a5 View commit details

Commits on Aug 14, 2024

  1. Add format_html() fixer (#478)

    For #477.
    adamchainz authored Aug 14, 2024
    Copy the full SHA
    b66ed85 View commit details

Commits on Aug 17, 2024

  1. Move CI to Ubuntu 24.04 (#483)

    Currently in beta (see https://github.com/actions/runner-images) but
    should be stable enough for us.
    adamchainz authored Aug 17, 2024
    Copy the full SHA
    2eb9dea View commit details

Commits on Aug 24, 2024

  1. Copy the full SHA
    b462175 View commit details

Commits on Aug 26, 2024

  1. [pre-commit.ci] pre-commit autoupdate (#486)

    <!--pre-commit.ci start-->
    updates:
    - [github.com/pre-commit/mirrors-mypy: v1.11.1 →
    v1.11.2](pre-commit/mirrors-mypy@v1.11.1...v1.11.2)
    <!--pre-commit.ci end-->
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    pre-commit-ci[bot] authored Aug 26, 2024
    Copy the full SHA
    ab52f96 View commit details

Commits on Sep 5, 2024

  1. Version 1.21.0

    adamchainz committed Sep 5, 2024
    Copy the full SHA
    090f59d View commit details
  2. Copy the full SHA
    0a311ed View commit details
  3. Copy the full SHA
    94f912f View commit details
  4. Copy the full SHA
    dc409e9 View commit details

Commits on Sep 6, 2024

  1. Use uv on GitHub Actions (#489)

    Gives a nice speed boost.
    adamchainz authored Sep 6, 2024
    Copy the full SHA
    65b287e View commit details

Commits on Sep 7, 2024

  1. Copy the full SHA
    92085d1 View commit details

Commits on Sep 9, 2024

  1. Copy the full SHA
    ea0381e View commit details

Commits on Oct 2, 2024

  1. Bump astral-sh/setup-uv from 1 to 3 in the github-actions group (#493)

    Bumps the github-actions group with 1 update:
    [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv).
    
    ---------
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Adam Johnson <me@adamj.eu>
    dependabot[bot] and adamchainz authored Oct 2, 2024
    Copy the full SHA
    0241f62 View commit details

Commits on Oct 8, 2024

  1. [pre-commit.ci] pre-commit autoupdate (#494)

    <!--pre-commit.ci start-->
    updates:
    - [github.com/pre-commit/pre-commit-hooks: v4.6.0 →
    v5.0.0](pre-commit/pre-commit-hooks@v4.6.0...v5.0.0)
    - [github.com/tox-dev/pyproject-fmt: 2.2.1 →
    2.2.4](tox-dev/pyproject-fmt@2.2.1...2.2.4)
    - [github.com/tox-dev/tox-ini-fmt: 1.3.1 →
    1.4.1](tox-dev/tox-ini-fmt@1.3.1...1.4.1)
    <!--pre-commit.ci end-->
    
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    pre-commit-ci[bot] authored Oct 8, 2024
    Copy the full SHA
    760f1f0 View commit details

Commits on Oct 10, 2024

  1. Avoid accidental removal of trailing comments (#496)

    Fixes #495.
    
    ---------
    
    Co-authored-by: Tobias Funke <tfunke@bona-fide.it>
    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Adam Johnson <me@adamj.eu>
    4 people authored Oct 10, 2024
    Copy the full SHA
    c219454 View commit details
  2. Copy the full SHA
    3b1421f View commit details
  3. Add test skip decorator fixer (#498)

    Start of #364.
    adamchainz authored Oct 10, 2024
    Copy the full SHA
    666a6ce View commit details
  4. Copy the full SHA
    14eae88 View commit details
  5. Copy the full SHA
    ee96e50 View commit details
  6. Copy the full SHA
    0d1660b View commit details
  7. Copy the full SHA
    2f4d1c2 View commit details
  8. Version 1.22.0

    adamchainz committed Oct 10, 2024
    Copy the full SHA
    675d2f7 View commit details

Commits on Oct 11, 2024

  1. Fix circular import error (#505)

    Fixes #503.
    adamchainz authored Oct 11, 2024
    Copy the full SHA
    ea6abce View commit details
  2. Version 1.22.1

    adamchainz committed Oct 11, 2024
    Copy the full SHA
    55b9d90 View commit details
Showing with 1,788 additions and 703 deletions.
  1. +1 −1 .github/dependabot.yml
  2. +38 −9 .github/workflows/main.yml
  3. +11 −8 .pre-commit-config.yaml
  4. +29 −0 CHANGELOG.rst
  5. +79 −6 README.rst
  6. +10 −3 pyproject.toml
  7. +0 −92 requirements/py310.txt
  8. +0 −82 requirements/py311.txt
  9. +0 −82 requirements/py312.txt
  10. +0 −100 requirements/py38.txt
  11. +0 −100 requirements/py39.txt
  12. +44 −0 src/django_upgrade/ast.py
  13. +0 −21 src/django_upgrade/compat.py
  14. +7 −6 src/django_upgrade/data.py
  15. +1 −1 src/django_upgrade/fixers/admin_allow_tags.py
  16. +2 −2 src/django_upgrade/fixers/admin_decorators.py
  17. +1 −1 src/django_upgrade/fixers/admin_lookup_needs_distinct.py
  18. +3 −3 src/django_upgrade/fixers/admin_register.py
  19. +1 −1 src/django_upgrade/fixers/assert_form_error.py
  20. +1 −1 src/django_upgrade/fixers/assert_set_methods.py
  21. +26 −29 src/django_upgrade/fixers/check_constraint_condition.py
  22. +2 −2 src/django_upgrade/fixers/compatibility_imports.py
  23. +1 −1 src/django_upgrade/fixers/crypto_get_random_string.py
  24. +1 −1 src/django_upgrade/fixers/default_app_config.py
  25. +4 −6 src/django_upgrade/fixers/django_urls.py
  26. +1 −1 src/django_upgrade/fixers/email_validator.py
  27. +73 −0 src/django_upgrade/fixers/format_html.py
  28. +1 −1 src/django_upgrade/fixers/forms_model_multiple_choice_field.py
  29. +2 −3 src/django_upgrade/fixers/index_together.py
  30. +1 −1 src/django_upgrade/fixers/management_commands.py
  31. +1 −1 src/django_upgrade/fixers/null_boolean_field.py
  32. +2 −2 src/django_upgrade/fixers/on_delete.py
  33. +1 −1 src/django_upgrade/fixers/password_reset_timeout_days.py
  34. +1 −1 src/django_upgrade/fixers/postgres_float_range_field.py
  35. +1 −1 src/django_upgrade/fixers/queryset_paginator.py
  36. +5 −19 src/django_upgrade/fixers/request_headers.py
  37. +1 −1 src/django_upgrade/fixers/request_user_attributes.py
  38. +1 −1 src/django_upgrade/fixers/settings_database_postgresql.py
  39. +2 −2 src/django_upgrade/fixers/settings_storages.py
  40. +1 −1 src/django_upgrade/fixers/signal_providing_args.py
  41. +30 −34 src/django_upgrade/fixers/test_http_headers.py
  42. +1 −1 src/django_upgrade/fixers/testcase_databases.py
  43. +1 −1 src/django_upgrade/fixers/timezone_fixedoffset.py
  44. +1 −1 src/django_upgrade/fixers/use_l10n.py
  45. +1 −1 src/django_upgrade/fixers/utils_encoding.py
  46. +1 −1 src/django_upgrade/fixers/utils_http.py
  47. +1 −1 src/django_upgrade/fixers/utils_text.py
  48. +2 −2 src/django_upgrade/fixers/utils_timezone.py
  49. +1 −1 src/django_upgrade/fixers/utils_translation.py
  50. +7 −39 src/django_upgrade/fixers/versioned_branches.py
  51. +120 −0 src/django_upgrade/fixers/versioned_test_skip_decorators.py
  52. +3 −4 src/django_upgrade/main.py
  53. +30 −4 src/django_upgrade/tokens.py
  54. +0 −4 tests/fixers/test_admin_register.py
  55. +0 −6 tests/fixers/test_check_constraint_condition.py
  56. +160 −0 tests/fixers/test_format_html.py
  57. +0 −6 tests/fixers/test_test_http_headers.py
  58. +35 −0 tests/fixers/test_versioned_branches.py
  59. +486 −0 tests/fixers/test_versioned_test_skip_decorators.py
  60. +1 −1 { → tests}/requirements/compile.py
  61. +112 −0 tests/requirements/py310.txt
  62. +102 −0 tests/requirements/py311.txt
  63. +102 −0 tests/requirements/py312.txt
  64. +102 −0 tests/requirements/py313.txt
  65. +120 −0 tests/requirements/py39.txt
  66. 0 { → tests}/requirements/requirements.in
  67. +11 −0 tests/test_main.py
  68. +2 −2 tox.ini
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -7,4 +7,4 @@ updates:
patterns:
- "*"
schedule:
interval: weekly
interval: monthly
47 changes: 38 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@ on:
push:
branches:
- main
tags:
- '**'
pull_request:

concurrency:
@@ -13,16 +15,16 @@ concurrency:
jobs:
tests:
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04

strategy:
matrix:
python-version:
- 3.8
- 3.9
- '3.10'
- '3.11'
- '3.12'
- '3.13'

steps:
- uses: actions/checkout@v4
@@ -31,13 +33,15 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: pip
cache-dependency-path: 'requirements/*.txt'

- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: tests/requirements/*.txt

- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install --upgrade 'tox>=4.0.0rc3'
run: uv pip install --system tox tox-uv

- name: Run tox targets for ${{ matrix.python-version }}
run: tox run -f py$(echo ${{ matrix.python-version }} | tr -d .)
@@ -47,10 +51,12 @@ jobs:
with:
name: coverage-data-${{ matrix.python-version }}
path: '${{ github.workspace }}/.coverage.*'
include-hidden-files: true
if-no-files-found: error

coverage:
name: Coverage
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
needs: tests
steps:
- uses: actions/checkout@v4
@@ -59,8 +65,11 @@ jobs:
with:
python-version: '3.12'

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Install dependencies
run: python -m pip install --upgrade coverage[toml]
run: uv pip install --system coverage[toml]

- name: Download data
uses: actions/download-artifact@v4
@@ -83,3 +92,23 @@ jobs:
with:
name: html-report
path: htmlcov

release:
needs: [coverage]
if: success() && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-24.04
environment: release

permissions:
contents: read
id-token: write

steps:
- uses: actions/checkout@v4

- uses: astral-sh/setup-uv@v3

- name: Build
run: uv build

- uses: pypa/gh-action-pypi-publish@release/v1
19 changes: 11 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
ci:
autoupdate_schedule: monthly

default_language_version:
python: python3.12

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
@@ -14,11 +17,11 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 2.1.4
rev: 2.2.4
hooks:
- id: pyproject-fmt
- repo: https://github.com/tox-dev/tox-ini-fmt
rev: 1.3.1
rev: 1.4.1
hooks:
- id: tox-ini-fmt
- repo: https://github.com/rstcheck/rstcheck
@@ -28,12 +31,12 @@ repos:
additional_dependencies:
- tomli==2.0.1
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py38-plus]
args: [--py39-plus]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.4.2
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/adamchainz/blacken-docs
@@ -48,7 +51,7 @@ repos:
- id: isort
name: isort (python)
- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies:
@@ -57,7 +60,7 @@ repos:
- flake8-logging
- flake8-tidy-imports
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies:
29 changes: 29 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -2,6 +2,35 @@
Changelog
=========

1.22.1 (2024-10-11)
-------------------

* Fix circular import error when running django-upgrade.

Thanks to Michal Čihař for the report in `Issue #503 <https://github.com/adamchainz/django-upgrade/issues/503>`__.

1.22.0 (2024-10-10)
-------------------

* Avoid accidental removal of comments a removed ``if`` block in the versioned block fixer.

Thanks to Tobias Funke for the report in `Issue #495 <https://github.com/adamchainz/django-upgrade/issues/495>`__.

* Add all-version fixer to remove outdated test skip decorators.

`Issue #364 <https://github.com/adamchainz/django-upgrade/issues/364>`__.

* Drop Python 3.8 support.

* Support Python 3.13.

1.21.0 (2024-09-05)
-------------------

* Add Django 5.0+ fixer to rewrite ``format_html()`` calls without ``args`` or ``kwargs`` probably using ``str.format()`` incorrectly.

`Issue #477 <https://github.com/adamchainz/django-upgrade/issues/477>`__.

1.20.0 (2024-07-19)
-------------------

85 changes: 79 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ Use **pip**:
python -m pip install django-upgrade
Python 3.8 to 3.12 supported.
Python 3.9 to 3.13 supported.

(Python 3.12+ is required to correctly apply fixes within f-strings.)

@@ -218,6 +218,66 @@ A single ``else`` block may be present, but ``elif`` is not supported.
See also `pyupgrade’s similar feature <https://github.com/asottile/pyupgrade/#python2-and-old-python3x-blocks>`__ that removes outdated code from checks on the Python version.

Versioned test skip decorators
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Name:** ``versioned_test_skip_decorators``

Removes outdated test skip decorators that compare to ``django.VERSION``.
Like the above, it requires comparisons of the form:

.. code-block:: text
django.VERSION <comparator> (<X>, <Y>)
Supports these test skip decorators:

* |unittest.skipIf|__

.. |unittest.skipIf| replace:: ``@unittest.skipIf``
__ https://docs.python.org/3/library/unittest.html#unittest.skipIf

* |unittest.skipUnless|__

.. |unittest.skipUnless| replace:: ``@unittest.skipUnless``
__ https://docs.python.org/3/library/unittest.html#unittest.skipUnless

* |pytest.mark.skipif|__

.. |pytest.mark.skipif| replace:: ``@pytest.mark.skipif``
__ https://docs.pytest.org/en/stable/how-to/skipping.html#id1

For example:

.. code-block:: diff
import unittest
import django
import pytest
from django.test import TestCase
class ExampleTests(TestCase):
- @unittest.skipIf(django.VERSION < (5, 1), "Django 5.1+")
def test_one(self):
...
- @unittest.skipUnless(django.VERSION >= (5, 1), "Django 5.1+")
def test_two(self):
...
- @pytest.mark.skipif(django.VERSION < (5, 1), reason="Django 5.1+")
def test_three(self):
...
-@unittest.skipIf(django.VERSION < (5, 1), "Django 5.1+")
class Example2Tests(TestCase):
...
-@pytest.mark.skipif(django.VERSION < (5, 1), reason="Django 5.1+")
class Example3Tests(TestCase):
...
Django 5.1
----------

@@ -230,8 +290,6 @@ Django 5.1

Rewrites calls to ``CheckConstraint`` and built-in subclasses from the old ``check`` argument to the new name ``condition``.

Requires Python 3.9+ due to changes in ``ast.keyword``.

.. code-block:: diff
-CheckConstraint(check=Q(amount__gte=0))
@@ -242,7 +300,24 @@ Django 5.0

`Release Notes <https://docs.djangoproject.com/en/5.0/releases/5.0/>`__

No fixers yet.
``format_html()`` calls
~~~~~~~~~~~~~~~~~~~~~~~

**Name:** ``format_html``

Rewrites ``format_html()`` calls without ``args`` or ``kwargs`` but using ``str.format()``.
Such calls are most likely incorrectly applying formatting without escaping, making them vulnerable to HTML injection.
Such use cases are why calling ``format_html()`` without any arguments or keyword arguments was deprecated in `Ticket #34609 <https://code.djangoproject.com/ticket/34609>`__.

.. code-block:: diff
from django.utils.html import format_html
-format_html("<marquee>{}</marquee>".format(message))
+format_html("<marquee>{}</marquee>", message)
-format_html("<marquee>{name}</marquee>".format(name=name))
+format_html("<marquee>{name}</marquee>", name=name)
Django 4.2
----------
@@ -298,8 +373,6 @@ Transforms HTTP headers from the old WSGI kwarg format to use the new ``headers`
* ``Client`` instantiation
* ``RequestFactory`` instantiation

Requires Python 3.9+ due to changes in ``ast.keyword``.

.. code-block:: diff
-response = self.client.get("/", HTTP_ACCEPT="text/plain")
13 changes: 10 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ requires = [

[project]
name = "django-upgrade"
version = "1.20.0"
version = "1.22.1"
description = "Automatically upgrade your Django project code."
readme = "README.rst"
keywords = [
@@ -15,7 +15,7 @@ keywords = [
authors = [
{ name = "Adam Johnson", email = "me@adamj.eu" },
]
requires-python = ">=3.8"
requires-python = ">=3.9"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Framework :: Django :: 2.2",
@@ -31,11 +31,11 @@ classifiers = [
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Typing :: Typed",
]
dependencies = [
@@ -51,11 +51,15 @@ add_imports = [
force_single_line = true
profile = "black"

[tool.pyproject-fmt]
max_supported_python = "3.13"

[tool.pytest.ini_options]
addopts = """\
--strict-config
--strict-markers
"""
xfail_strict = true

[tool.coverage.run]
branch = true
@@ -73,6 +77,9 @@ source = [

[tool.coverage.report]
show_missing = true
exclude_also = [
"if TYPE_CHECKING:",
]

[tool.mypy]
enable_error_code = [
Loading