diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d1972c080070..dbe92a2bdc39 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/psf/black-pre-commit-mirror - rev: 25.12.0 + rev: 26.1.0 hooks: - id: black exclude: \.py-tpl$ @@ -9,7 +9,7 @@ repos: hooks: - id: blacken-docs additional_dependencies: - - black==25.12.0 + - black==26.1.0 files: 'docs/.*\.txt$' args: ["--rst-literal-block"] - repo: https://github.com/PyCQA/isort diff --git a/django/contrib/gis/gdal/envelope.py b/django/contrib/gis/gdal/envelope.py index f33f9b4df6bb..b1ed69ca074e 100644 --- a/django/contrib/gis/gdal/envelope.py +++ b/django/contrib/gis/gdal/envelope.py @@ -128,7 +128,7 @@ def expand_to_include(self, *args): (args[0][0], args[0][1], args[0][0], args[0][1]) ) elif len(args[0]) == 4: - (minx, miny, maxx, maxy) = args[0] + minx, miny, maxx, maxy = args[0] if minx < self._envelope.MinX: self._envelope.MinX = minx if miny < self._envelope.MinY: diff --git a/django/contrib/gis/geos/mutable_list.py b/django/contrib/gis/geos/mutable_list.py index 36131fe9cea2..0a74bc59e2cf 100644 --- a/django/contrib/gis/geos/mutable_list.py +++ b/django/contrib/gis/geos/mutable_list.py @@ -8,6 +8,7 @@ Author: Aryeh Leib Taurog. """ + from functools import total_ordering diff --git a/django/contrib/gis/measure.py b/django/contrib/gis/measure.py index 71dc130ac4e0..d04fcbcb1e47 100644 --- a/django/contrib/gis/measure.py +++ b/django/contrib/gis/measure.py @@ -36,6 +36,7 @@ Inspired by GeoPy (https://github.com/geopy/geopy) and Geoff Biggs' PhD work on dimensioned units for robotics. """ + from decimal import Decimal from functools import total_ordering diff --git a/django/contrib/gis/utils/layermapping.py b/django/contrib/gis/utils/layermapping.py index a4cd04dc057a..e55737885941 100644 --- a/django/contrib/gis/utils/layermapping.py +++ b/django/contrib/gis/utils/layermapping.py @@ -6,6 +6,7 @@ For more information, please consult the GeoDjango documentation: https://docs.djangoproject.com/en/dev/ref/contrib/gis/layermapping/ """ + import sys from decimal import Decimal from decimal import InvalidOperation as DecimalInvalidOperation diff --git a/django/core/checks/__init__.py b/django/core/checks/__init__.py index 2502450cdfa9..faca2a337d0b 100644 --- a/django/core/checks/__init__.py +++ b/django/core/checks/__init__.py @@ -28,7 +28,6 @@ import django.core.checks.translation # NOQA isort:skip import django.core.checks.urls # NOQA isort:skip - __all__ = [ "CheckMessage", "Debug", diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py index ff7ee45557f4..7eb6a4b157af 100644 --- a/django/core/management/commands/flush.py +++ b/django/core/management/commands/flush.py @@ -57,15 +57,12 @@ def handle(self, **options): ) if interactive: - confirm = input( - """You have requested a flush of the database. + confirm = input("""You have requested a flush of the database. This will IRREVERSIBLY DESTROY all data currently in the "%s" database, and return each table to an empty state. Are you sure you want to do this? - Type 'yes' to continue, or 'no' to cancel: """ - % connection.settings_dict["NAME"] - ) + Type 'yes' to continue, or 'no' to cancel: """ % connection.settings_dict["NAME"]) else: confirm = "yes" diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 514db70d235f..74406fe94055 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -399,16 +399,14 @@ def mysql_server_data(self): # Select some server variables and test if the time zone # definitions are installed. CONVERT_TZ returns NULL if 'UTC' # timezone isn't loaded into the mysql.time_zone table. - cursor.execute( - """ + cursor.execute(""" SELECT VERSION(), @@sql_mode, @@default_storage_engine, @@sql_auto_is_null, @@lower_case_table_names, CONVERT_TZ('2001-01-01 01:00:00', 'UTC', 'UTC') IS NOT NULL - """ - ) + """) row = cursor.fetchone() return { "version": row[0], diff --git a/django/db/backends/mysql/introspection.py b/django/db/backends/mysql/introspection.py index 59105b4e7632..ac8f471e1b6f 100644 --- a/django/db/backends/mysql/introspection.py +++ b/django/db/backends/mysql/introspection.py @@ -79,16 +79,14 @@ def get_field_type(self, data_type, description): def get_table_list(self, cursor): """Return a list of table and view names in the current database.""" - cursor.execute( - """ + cursor.execute(""" SELECT table_name, table_type, table_comment FROM information_schema.tables WHERE table_schema = DATABASE() - """ - ) + """) return [ TableInfo(row[0], {"BASE TABLE": "t", "VIEW": "v"}.get(row[1]), row[2]) for row in cursor.fetchall() diff --git a/django/db/backends/oracle/introspection.py b/django/db/backends/oracle/introspection.py index 07b7cad8402b..cbce6b10c004 100644 --- a/django/db/backends/oracle/introspection.py +++ b/django/db/backends/oracle/introspection.py @@ -59,8 +59,7 @@ def get_field_type(self, data_type, description): def get_table_list(self, cursor): """Return a list of table and view names in the current database.""" - cursor.execute( - """ + cursor.execute(""" SELECT user_tables.table_name, 't', @@ -79,8 +78,7 @@ def get_table_list(self, cursor): SELECT view_name, 'v', NULL FROM user_views UNION ALL SELECT mview_name, 'v', NULL FROM user_mviews - """ - ) + """) return [ TableInfo(self.identifier_converter(row[0]), row[1], row[2]) for row in cursor.fetchall() diff --git a/django/db/backends/postgresql/introspection.py b/django/db/backends/postgresql/introspection.py index 69dd776aa303..e1e61697424d 100644 --- a/django/db/backends/postgresql/introspection.py +++ b/django/db/backends/postgresql/introspection.py @@ -64,8 +64,7 @@ def get_field_type(self, data_type, description): def get_table_list(self, cursor): """Return a list of table and view names in the current database.""" - cursor.execute( - """ + cursor.execute(""" SELECT c.relname, CASE @@ -79,8 +78,7 @@ def get_table_list(self, cursor): WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid) - """ - ) + """) return [ TableInfo(*row) for row in cursor.fetchall() diff --git a/django/db/backends/sqlite3/introspection.py b/django/db/backends/sqlite3/introspection.py index b90f1265055f..fbd538a5e3cd 100644 --- a/django/db/backends/sqlite3/introspection.py +++ b/django/db/backends/sqlite3/introspection.py @@ -77,12 +77,10 @@ def get_table_list(self, cursor): """Return a list of table and view names in the current database.""" # Skip the sqlite_sequence system table used for autoincrement key # generation. - cursor.execute( - """ + cursor.execute(""" SELECT name, type FROM sqlite_master WHERE type in ('table', 'view') AND NOT name='sqlite_sequence' - ORDER BY name""" - ) + ORDER BY name""") return [TableInfo(row[0], row[1][0]) for row in cursor.fetchall()] def get_table_description(self, cursor, table_name): diff --git a/django/db/models/__init__.py b/django/db/models/__init__.py index 65123c3e85ff..b8f95526f756 100644 --- a/django/db/models/__init__.py +++ b/django/db/models/__init__.py @@ -72,7 +72,6 @@ OneToOneRel, ) - __all__ = aggregates_all + constraints_all + enums_all + fields_all + indexes_all __all__ += [ "ObjectDoesNotExist", diff --git a/django/template/__init__.py b/django/template/__init__.py index 92568da793a6..34f6e105bb1f 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -72,5 +72,4 @@ # Import the .autoreload module to trigger the registrations of signals. from . import autoreload # NOQA isort:skip - __all__ += ("Template", "Context", "RequestContext") diff --git a/django/test/runner.py b/django/test/runner.py index 5cd72119f5aa..6df7b87fabd1 100644 --- a/django/test/runner.py +++ b/django/test/runner.py @@ -207,8 +207,7 @@ def _confirm_picklable(self, obj): pickle.loads(pickle.dumps(obj)) def _print_unpicklable_subtest(self, test, subtest, pickle_exc): - print( - """ + print(""" Subtest failed: test: {} @@ -221,10 +220,7 @@ def _print_unpicklable_subtest(self, test, subtest, pickle_exc): You should re-run this test with --parallel=1 to reproduce the failure with a cleaner failure message. -""".format( - test, subtest, pickle_exc - ) - ) +""".format(test, subtest, pickle_exc)) def check_picklable(self, test, err): # Ensure that sys.exc_info() tuples are picklable. This displays a @@ -245,8 +241,7 @@ def check_picklable(self, test, err): pickle_exc_txt, 75, initial_indent=" ", subsequent_indent=" " ) if tblib is None: - print( - """ + print(""" {} failed: @@ -258,13 +253,9 @@ def check_picklable(self, test, err): In order to see the traceback, you should install tblib: python -m pip install tblib -""".format( - test, original_exc_txt - ) - ) +""".format(test, original_exc_txt)) else: - print( - """ + print(""" {} failed: @@ -279,10 +270,7 @@ def check_picklable(self, test, err): You should re-run this test with the --parallel=1 option to reproduce the failure and get a correct traceback. -""".format( - test, original_exc_txt, pickle_exc_txt - ) - ) +""".format(test, original_exc_txt, pickle_exc_txt)) raise def check_subtest_picklable(self, test, subtest): diff --git a/docs/_ext/djangodocs.py b/docs/_ext/djangodocs.py index 77e24ff0eb68..a979a8e30aca 100644 --- a/docs/_ext/djangodocs.py +++ b/docs/_ext/djangodocs.py @@ -83,9 +83,7 @@ def run(self): if len(self.arguments) > 1: msg = """Only one argument accepted for directive '{directive_name}::'. Comments should be provided as content, - not as an extra argument.""".format( - directive_name=self.name - ) + not as an extra argument.""".format(directive_name=self.name) raise self.error(msg) env = self.state.document.settings.env @@ -255,17 +253,14 @@ def visit_console_html(self, node): # has been used on it. self.document._console_directive_used_flag = True uid = node["uid"] - self.body.append( - """\ + self.body.append("""\
";') - parse_html( - """ + parse_html(""" - """ - ) + """) # script content will be parsed to text - dom = parse_html( - """ + dom = parse_html(""" - """ - ) + """) self.assertEqual(len(dom.children), 1) self.assertEqual(dom.children[0], "
foo
'' bar") @@ -1022,12 +1018,10 @@ def test_escaped_html_errors(self): self.assertHTMLEqual("<foo>
") def test_contains_html(self): - response = HttpResponse( - """ + response = HttpResponse(""" This is a form: """ - ) + """) self.assertNotContains(response, "") self.assertContains(response, '