From 6cff02078799b7c683a0d39630d49ab4fe532e7c Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Sun, 18 Jan 2026 21:26:56 +0100 Subject: [PATCH] Applied Black's 2026 stable style. https://github.com/psf/black/releases/tag/26.1.0 --- .pre-commit-config.yaml | 4 +- django/contrib/gis/gdal/envelope.py | 2 +- django/contrib/gis/geos/mutable_list.py | 1 + django/contrib/gis/measure.py | 1 + django/contrib/gis/utils/layermapping.py | 1 + django/core/checks/__init__.py | 1 - django/core/management/commands/flush.py | 7 +- django/db/backends/mysql/base.py | 6 +- django/db/backends/mysql/introspection.py | 6 +- django/db/backends/oracle/introspection.py | 6 +- .../db/backends/postgresql/introspection.py | 6 +- django/db/backends/sqlite3/introspection.py | 6 +- django/db/models/__init__.py | 1 - django/template/__init__.py | 1 - django/test/runner.py | 24 ++---- docs/_ext/djangodocs.py | 11 +-- docs/howto/custom-template-tags.txt | 1 - docs/ref/contrib/gis/gdal.txt | 6 +- docs/ref/contrib/postgres/constraints.txt | 1 - docs/topics/db/sql.txt | 7 +- docs/topics/tasks.txt | 2 - tests/auth_tests/test_forms.py | 10 +-- tests/backends/mysql/test_introspection.py | 12 +-- tests/csrf_tests/views.py | 6 +- tests/forms_tests/tests/test_forms.py | 3 +- tests/forms_tests/tests/tests.py | 3 +- .../widget_tests/test_clearablefileinput.py | 24 ++---- .../widget_tests/test_multiwidget.py | 6 +- .../widget_tests/test_nullbooleanselect.py | 60 +++++--------- tests/forms_tests/widget_tests/test_select.py | 78 +++++++------------ .../widget_tests/test_selectdatewidget.py | 30 +++---- .../widget_tests/test_selectmultiple.py | 60 +++++--------- .../test_splithiddendatetimewidget.py | 6 +- tests/generic_relations/test_forms.py | 3 +- tests/i18n/patterns/tests.py | 24 ++---- tests/m2m_through_regress/tests.py | 3 +- tests/mail/tests.py | 6 +- tests/migrations/test_multidb.py | 4 +- tests/model_forms/test_modelchoicefield.py | 3 +- tests/model_forms/tests.py | 10 +-- tests/postgres_tests/test_array.py | 6 +- tests/requirements/py3.txt | 2 +- tests/serializers/test_deserialization.py | 6 +- tests/sitemaps_tests/test_http.py | 16 +--- tests/sphinx/test_github_links.py | 6 +- tests/test_runner/test_parallel.py | 2 +- tests/test_utils/tests.py | 22 ++---- 47 files changed, 171 insertions(+), 341 deletions(-) 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("""\
-
\n""" - % {"id": uid} - ) +
\n""" % {"id": uid}) try: self.visit_literal_block(node) except nodes.SkipNode: diff --git a/docs/howto/custom-template-tags.txt b/docs/howto/custom-template-tags.txt index 0a946b7c50a7..49b9939036b5 100644 --- a/docs/howto/custom-template-tags.txt +++ b/docs/howto/custom-template-tags.txt @@ -599,7 +599,6 @@ implemented using a ``simple_block_tag`` as follows: from django import template from django.utils.html import format_html - register = template.Library() diff --git a/docs/ref/contrib/gis/gdal.txt b/docs/ref/contrib/gis/gdal.txt index 15bfc6641f0f..44383b24a134 100644 --- a/docs/ref/contrib/gis/gdal.txt +++ b/docs/ref/contrib/gis/gdal.txt @@ -1072,8 +1072,7 @@ Coordinate System Objects >>> wgs84 = SpatialReference("EPSG:4326") # EPSG string >>> proj = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs " >>> wgs84 = SpatialReference(proj) # PROJ string - >>> wgs84 = SpatialReference( - ... """GEOGCS["WGS 84", + >>> wgs84 = SpatialReference("""GEOGCS["WGS 84", ... DATUM["WGS_1984", ... SPHEROID["WGS 84",6378137,298.257223563, ... AUTHORITY["EPSG","7030"]], @@ -1082,8 +1081,7 @@ Coordinate System Objects ... AUTHORITY["EPSG","8901"]], ... UNIT["degree",0.01745329251994328, ... AUTHORITY["EPSG","9122"]], - ... AUTHORITY["EPSG","4326"]]""" - ... ) # OGC WKT + ... AUTHORITY["EPSG","4326"]]""") # OGC WKT .. method:: __getitem__(target) diff --git a/docs/ref/contrib/postgres/constraints.txt b/docs/ref/contrib/postgres/constraints.txt index 29083c0b6b91..b3d84e9bfdde 100644 --- a/docs/ref/contrib/postgres/constraints.txt +++ b/docs/ref/contrib/postgres/constraints.txt @@ -105,7 +105,6 @@ are ``Deferrable.DEFERRED`` or ``Deferrable.IMMEDIATE``. For example:: from django.contrib.postgres.fields import RangeOperators from django.db.models import Deferrable - ExclusionConstraint( name="exclude_overlapping_deferred", expressions=[ diff --git a/docs/topics/db/sql.txt b/docs/topics/db/sql.txt index 6aafa2c3b543..bd34df8bb73a 100644 --- a/docs/topics/db/sql.txt +++ b/docs/topics/db/sql.txt @@ -121,15 +121,14 @@ had ``Person`` data in it, you could easily map it into ``Person`` instances: .. code-block:: pycon - >>> Person.objects.raw( - ... """ + >>> Person.objects.raw(""" ... SELECT first AS first_name, ... last AS last_name, ... bd AS birth_date, ... pk AS id, ... FROM some_other_table - ... """ - ... ) + ... """) + ... As long as the names match, the model instances will be created correctly. diff --git a/docs/topics/tasks.txt b/docs/topics/tasks.txt index 96deac6dc3de..06e83af0bc21 100644 --- a/docs/topics/tasks.txt +++ b/docs/topics/tasks.txt @@ -207,7 +207,6 @@ To receive the Task context as an argument to your Task function, pass from django.core.mail import send_mail from django.tasks import task - logger = logging.getLogger(__name__) @@ -328,7 +327,6 @@ committed to the database, use :func:`transaction.on_commit() from django.db import transaction - with transaction.atomic(): Thing.objects.create(num=1) transaction.on_commit(partial(my_task.enqueue, thing_num=1)) diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index 73065adddf40..983fe8c39e80 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -1234,7 +1234,7 @@ def test_nonexistent_email(self): self.assertEqual(len(mail.outbox), 0) def test_cleaned_data(self): - (user, username, email) = self.create_dummy_user() + user, username, email = self.create_dummy_user() data = {"email": email} form = PasswordResetForm(data) self.assertTrue(form.is_valid()) @@ -1303,7 +1303,7 @@ def test_inactive_user(self): """ Inactive user cannot receive password reset email. """ - (user, username, email) = self.create_dummy_user() + user, username, email = self.create_dummy_user() user.is_active = False user.save() form = PasswordResetForm({"email": email}) @@ -1330,7 +1330,7 @@ def test_save_plaintext_email(self): html_email_template_name parameter passed in. Test to ensure original behavior is unchanged after the parameter was added. """ - (user, username, email) = self.create_dummy_user() + user, username, email = self.create_dummy_user() form = PasswordResetForm({"email": email}) self.assertTrue(form.is_valid()) form.save() @@ -1352,7 +1352,7 @@ def test_save_html_email_template_name(self): Test to ensure that a multipart email is sent with both text/plain and text/html parts. """ - (user, username, email) = self.create_dummy_user() + user, username, email = self.create_dummy_user() form = PasswordResetForm({"email": email}) self.assertTrue(form.is_valid()) form.save( @@ -1382,7 +1382,7 @@ def test_save_html_email_template_name(self): @override_settings(EMAIL_BACKEND="mail.custombackend.FailingEmailBackend") def test_save_send_email_exceptions_are_catched_and_logged(self): - (user, username, email) = self.create_dummy_user() + user, username, email = self.create_dummy_user() form = PasswordResetForm({"email": email}) self.assertTrue(form.is_valid()) diff --git a/tests/backends/mysql/test_introspection.py b/tests/backends/mysql/test_introspection.py index a2e2938451a9..55272989d254 100644 --- a/tests/backends/mysql/test_introspection.py +++ b/tests/backends/mysql/test_introspection.py @@ -81,19 +81,16 @@ def test_omit_cross_database_relations(self): rel_column_quoted = other_connection.ops.quote_name(rel_column) try: with other_connection.cursor() as other_cursor: - other_cursor.execute( - f""" + other_cursor.execute(f""" CREATE TABLE {rel_table_quoted} ( id integer AUTO_INCREMENT, PRIMARY KEY (id) ) - """ - ) + """) with default_connection.cursor() as default_cursor: # Create table in the default schema with a cross-database # relation. - default_cursor.execute( - f""" + default_cursor.execute(f""" CREATE TABLE {main_table_quoted} ( id integer AUTO_INCREMENT, {rel_column_quoted} integer NOT NULL, @@ -101,8 +98,7 @@ def test_omit_cross_database_relations(self): FOREIGN KEY ({rel_column_quoted}) REFERENCES {other_schema_quoted}.{rel_table_quoted}(id) ) - """ - ) + """) relations = default_connection.introspection.get_relations( default_cursor, main_table ) diff --git a/tests/csrf_tests/views.py b/tests/csrf_tests/views.py index 2e8f0fcb0f15..3949aeaea1aa 100644 --- a/tests/csrf_tests/views.py +++ b/tests/csrf_tests/views.py @@ -62,13 +62,11 @@ def sandwiched_rotate_token_view(request): def post_form_view(request): """Return a POST form (without a token).""" - return HttpResponse( - content=""" + return HttpResponse(content="""

\u00a1Unicode!
-""" - ) +""") def token_view(request): diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 7f698ad706cd..14fbc19a598b 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -3671,7 +3671,8 @@ class FileForm(Form): self.assertTrue(f.is_valid()) file1 = SimpleUploadedFile( - "我隻氣墊船裝滿晒鱔.txt", "मेरी मँडराने वाली नाव सर्पमीनों से भरी ह".encode() + "我隻氣墊船裝滿晒鱔.txt", + "मेरी मँडराने वाली नाव सर्पमीनों से भरी ह".encode(), ) f = FileForm(data={}, files={"file1": file1}, auto_id=False) self.assertHTMLEqual( diff --git a/tests/forms_tests/tests/tests.py b/tests/forms_tests/tests/tests.py index 866faaac4d5b..253e34976aa5 100644 --- a/tests/forms_tests/tests/tests.py +++ b/tests/forms_tests/tests/tests.py @@ -250,7 +250,8 @@ class FormsModelTestCase(TestCase): def test_unicode_filename(self): # FileModel with Unicode filename and data. file1 = SimpleUploadedFile( - "我隻氣墊船裝滿晒鱔.txt", "मेरी मँडराने वाली नाव सर्पमीनों से भरी ह".encode() + "我隻氣墊船裝滿晒鱔.txt", + "मेरी मँडराने वाली नाव सर्पमीनों से भरी ह".encode(), ) f = FileForm(data={}, files={"file1": file1}, auto_id=False) self.assertTrue(f.is_valid()) diff --git a/tests/forms_tests/widget_tests/test_clearablefileinput.py b/tests/forms_tests/widget_tests/test_clearablefileinput.py index ae54cc4b5da9..31ff1af624e2 100644 --- a/tests/forms_tests/widget_tests/test_clearablefileinput.py +++ b/tests/forms_tests/widget_tests/test_clearablefileinput.py @@ -29,14 +29,12 @@ def test_clear_input_renders(self): self.widget, "myfile", FakeFieldFile(), - html=( - """ + html=(""" Currently: something
Change: - """ - ), + """), ) def test_html_escaped(self): @@ -55,8 +53,7 @@ def __str__(self): ClearableFileInput(), "my
file", StrangeFieldFile(), - html=( - """ + html=(""" Currently: something<div onclick="alert('oops')">.jpg @@ -64,8 +61,7 @@ def __str__(self): id="my<div>file-clear_id">
Change: - """ - ), + """), ) def test_clear_input_renders_only_if_not_required(self): @@ -79,12 +75,10 @@ def test_clear_input_renders_only_if_not_required(self): widget, "myfile", FakeFieldFile(), - html=( - """ + html=(""" Currently: something
Change: - """ - ), + """), ) def test_clear_input_renders_only_if_initial(self): @@ -143,14 +137,12 @@ def test_render_as_subwidget(self): widget, "myfile", [FakeFieldFile()], - html=( - """ + html=(""" Currently: something
Change: - """ - ), + """), ) def test_clear_input_checked_returns_false(self): diff --git a/tests/forms_tests/widget_tests/test_multiwidget.py b/tests/forms_tests/widget_tests/test_multiwidget.py index 40f099e62542..5e360e3e92d7 100644 --- a/tests/forms_tests/widget_tests/test_multiwidget.py +++ b/tests/forms_tests/widget_tests/test_multiwidget.py @@ -273,8 +273,7 @@ def test_nested_multiwidget(self): widget, "name", "some text,JP,2007-04-25 06:24:00", - html=( - """ + html=(""" - """ - ), + """), ) def test_no_whitespace_between_widgets(self): diff --git a/tests/forms_tests/widget_tests/test_nullbooleanselect.py b/tests/forms_tests/widget_tests/test_nullbooleanselect.py index 307ae5657933..705ec6ce06f9 100644 --- a/tests/forms_tests/widget_tests/test_nullbooleanselect.py +++ b/tests/forms_tests/widget_tests/test_nullbooleanselect.py @@ -12,13 +12,11 @@ def test_render_true(self): self.widget, "is_cool", True, - html=( - """ - """ - ), + """), ) def test_render_false(self): @@ -26,13 +24,11 @@ def test_render_false(self): self.widget, "is_cool", False, - html=( - """ - """ - ), + """), ) def test_render_none(self): @@ -40,13 +36,11 @@ def test_render_none(self): self.widget, "is_cool", None, - html=( - """ - """ - ), + """), ) def test_render_value_unknown(self): @@ -54,13 +48,11 @@ def test_render_value_unknown(self): self.widget, "is_cool", "unknown", - html=( - """ - """ - ), + """), ) def test_render_value_true(self): @@ -68,13 +60,11 @@ def test_render_value_true(self): self.widget, "is_cool", "true", - html=( - """ - """ - ), + """), ) def test_render_value_false(self): @@ -82,13 +72,11 @@ def test_render_value_false(self): self.widget, "is_cool", "false", - html=( - """ - """ - ), + """), ) def test_render_value_1(self): @@ -96,13 +84,11 @@ def test_render_value_1(self): self.widget, "is_cool", "1", - html=( - """ - """ - ), + """), ) def test_render_value_2(self): @@ -110,13 +96,11 @@ def test_render_value_2(self): self.widget, "is_cool", "2", - html=( - """ - """ - ), + """), ) def test_render_value_3(self): @@ -124,13 +108,11 @@ def test_render_value_3(self): self.widget, "is_cool", "3", - html=( - """ - """ - ), + """), ) def test_l10n(self): @@ -144,15 +126,13 @@ def test_l10n(self): widget, "id_bool", True, - html=( - """ + html=(""" - """ - ), + """), ) def test_fieldset(self): diff --git a/tests/forms_tests/widget_tests/test_select.py b/tests/forms_tests/widget_tests/test_select.py index 6164d0b6b369..884b76808681 100644 --- a/tests/forms_tests/widget_tests/test_select.py +++ b/tests/forms_tests/widget_tests/test_select.py @@ -31,14 +31,12 @@ def test_render_none(self): self.widget(choices=self.beatles), "beatle", None, - html=( - """ - """ - ), + """), ) def test_render_label_value(self): @@ -50,14 +48,12 @@ def test_render_label_value(self): self.widget(choices=self.beatles), "beatle", "John", - html=( - """ - """ - ), + """), ) def test_render_selected(self): @@ -70,15 +66,13 @@ def test_render_selected(self): self.widget(choices=choices), "choices", "0", - html=( - """ - """ - ), + """), ) def test_constructor_attrs(self): @@ -93,13 +87,11 @@ def test_constructor_attrs(self): widget, "num", 2, - html=( - """ - """ - ), + """), ) def test_compare_to_str(self): @@ -110,37 +102,31 @@ def test_compare_to_str(self): self.widget(choices=[("1", "1"), ("2", "2"), ("3", "3")]), "num", 2, - html=( - """ - """ - ), + """), ) self.check_html( self.widget(choices=[(1, 1), (2, 2), (3, 3)]), "num", "2", - html=( - """ - """ - ), + """), ) self.check_html( self.widget(choices=[(1, 1), (2, 2), (3, 3)]), "num", 2, - html=( - """ - """ - ), + """), ) def test_choices_constructor(self): @@ -149,13 +135,11 @@ def test_choices_constructor(self): widget, "num", 2, - html=( - """ - """ - ), + """), ) def test_choices_constructor_generator(self): @@ -173,29 +157,25 @@ def get_choices(): widget, "num", 2, - html=( - """ - """ - ), + """), ) self.check_html( widget, "num", 3, - html=( - """ - """ - ), + """), ) def test_choices_escaping(self): @@ -204,12 +184,10 @@ def test_choices_escaping(self): self.widget(choices=choices), "escape", None, - html=( - """ - """ - ), + """), ) def test_choices_unicode(self): @@ -217,8 +195,7 @@ def test_choices_unicode(self): self.widget(choices=[("ŠĐĆŽćžšđ", "ŠĐabcĆŽćžšđ"), ("ćžšđ", "abcćžšđ")]), "email", "ŠĐĆŽćžšđ", - html=( - """ + html=(""" - """ - ), + """), ) def test_choices_optgroup(self): @@ -429,8 +405,7 @@ def test_render_as_subwidget(self): MultiWidget([self.widget(choices=choices), TextInput()]), "beatle", ["J", "Some text"], - html=( - """ + html=(""" - """ - ), + """), ) def test_fieldset(self): diff --git a/tests/forms_tests/widget_tests/test_selectdatewidget.py b/tests/forms_tests/widget_tests/test_selectdatewidget.py index ff1f59a46c98..0a2dc3fc48d1 100644 --- a/tests/forms_tests/widget_tests/test_selectdatewidget.py +++ b/tests/forms_tests/widget_tests/test_selectdatewidget.py @@ -32,8 +32,7 @@ def test_render_empty(self): self.widget, "mydate", "", - html=( - """ + html=(""" - """ - ), + """), ) def test_render_none(self): @@ -116,8 +114,7 @@ def test_render_string(self): self.widget, "mydate", "2010-04-15", - html=( - """ + html=(""" - """ - ), + """), ) def test_render_datetime(self): @@ -200,8 +196,7 @@ def test_render_invalid_date(self): self.widget, "mydate", "2010-02-31", - html=( - """ + html=(""" - """ - ), + """), ) def test_custom_months(self): @@ -276,8 +270,7 @@ def test_custom_months(self): widget, "mydate", "", - html=( - """ + html=(""" - """ - ), + """), ) def test_selectdate_required(self): @@ -651,8 +643,7 @@ def test_years_rendered_without_separator(self): widget, "mydate", "", - html=( - """ + html=(""" - """ - ), + """), ) def test_fieldset(self): diff --git a/tests/forms_tests/widget_tests/test_selectmultiple.py b/tests/forms_tests/widget_tests/test_selectmultiple.py index c4fbea4490f7..e3dfee426d0f 100644 --- a/tests/forms_tests/widget_tests/test_selectmultiple.py +++ b/tests/forms_tests/widget_tests/test_selectmultiple.py @@ -18,14 +18,12 @@ def test_render_selected(self): self.widget(choices=self.beatles), "beatles", ["J"], - html=( - """ - """ - ), + """), ) def test_render_multiple_selected(self): @@ -33,14 +31,12 @@ def test_render_multiple_selected(self): self.widget(choices=self.beatles), "beatles", ["J", "P"], - html=( - """ - """ - ), + """), ) def test_render_none(self): @@ -52,15 +48,13 @@ def test_render_none(self): self.widget(choices=(("", "Unknown"),) + self.beatles), "beatles", None, - html=( - """ - """ - ), + """), ) def test_render_value_label(self): @@ -72,14 +66,12 @@ def test_render_value_label(self): self.widget(choices=self.beatles), "beatles", ["John"], - html=( - """ - """ - ), + """), ) def test_multiple_options_same_value(self): @@ -90,15 +82,13 @@ def test_multiple_options_same_value(self): self.widget(choices=self.numeric_choices), "choices", ["0"], - html=( - """ - """ - ), + """), ) def test_multiple_values_invalid(self): @@ -110,14 +100,12 @@ def test_multiple_values_invalid(self): self.widget(choices=self.beatles), "beatles", ["J", "G", "foo"], - html=( - """ - """ - ), + """), ) def test_compare_string(self): @@ -127,39 +115,33 @@ def test_compare_string(self): self.widget(choices=choices), "nums", [2], - html=( - """ - """ - ), + """), ) self.check_html( self.widget(choices=choices), "nums", ["2"], - html=( - """ - """ - ), + """), ) self.check_html( self.widget(choices=choices), "nums", [2], - html=( - """ - """ - ), + """), ) def test_optgroup_select_multiple(self): @@ -173,15 +155,13 @@ def test_optgroup_select_multiple(self): widget, "nestchoice", ["outer1", "inner2"], - html=( - """ - """ - ), + """), ) def test_value_omitted_from_data(self): diff --git a/tests/forms_tests/widget_tests/test_splithiddendatetimewidget.py b/tests/forms_tests/widget_tests/test_splithiddendatetimewidget.py index 93ded6ac6da7..1083ccc4ec87 100644 --- a/tests/forms_tests/widget_tests/test_splithiddendatetimewidget.py +++ b/tests/forms_tests/widget_tests/test_splithiddendatetimewidget.py @@ -56,12 +56,10 @@ def test_l10n(self): self.widget, "date", d, - html=( - """ + html=(""" - """ - ), + """), ) def test_constructor_different_attrs(self): diff --git a/tests/generic_relations/test_forms.py b/tests/generic_relations/test_forms.py index 00df254745e0..48fe895210ed 100644 --- a/tests/generic_relations/test_forms.py +++ b/tests/generic_relations/test_forms.py @@ -117,8 +117,7 @@ def test_output(self):

- """ - % tagged_item_id, + """ % tagged_item_id, ) lion = Animal.objects.create(common_name="Lion", latin_name="Panthera leo") formset = GenericFormSet(instance=lion, prefix="x") diff --git a/tests/i18n/patterns/tests.py b/tests/i18n/patterns/tests.py index bd329e69f8e7..1eb6d3d60f50 100644 --- a/tests/i18n/patterns/tests.py +++ b/tests/i18n/patterns/tests.py @@ -484,51 +484,43 @@ class URLTagTests(URLTestCaseBase): """ def test_strings_only(self): - t = Template( - """{% load i18n %} + t = Template("""{% load i18n %} {% language 'nl' %}{% url 'no-prefix-translated' %}{% endlanguage %} - {% language 'pt-br' %}{% url 'no-prefix-translated' %}{% endlanguage %}""" - ) + {% language 'pt-br' %}{% url 'no-prefix-translated' %}{% endlanguage %}""") self.assertEqual( t.render(Context({})).strip().split(), ["/vertaald/", "/traduzidos/"] ) def test_context(self): ctx = Context({"lang1": "nl", "lang2": "pt-br"}) - tpl = Template( - """{% load i18n %} + tpl = Template("""{% load i18n %} {% language lang1 %}{% url 'no-prefix-translated' %}{% endlanguage %} - {% language lang2 %}{% url 'no-prefix-translated' %}{% endlanguage %}""" - ) + {% language lang2 %}{% url 'no-prefix-translated' %}{% endlanguage %}""") self.assertEqual( tpl.render(ctx).strip().split(), ["/vertaald/", "/traduzidos/"] ) def test_args(self): - tpl = Template( - """ + tpl = Template(""" {% load i18n %} {% language 'nl' %} {% url 'no-prefix-translated-slug' 'apo' %}{% endlanguage %} {% language 'pt-br' %} {% url 'no-prefix-translated-slug' 'apo' %}{% endlanguage %} - """ - ) + """) self.assertEqual( tpl.render(Context({})).strip().split(), ["/vertaald/apo/", "/traduzidos/apo/"], ) def test_kwargs(self): - tpl = Template( - """ + tpl = Template(""" {% load i18n %} {% language 'nl' %} {% url 'no-prefix-translated-slug' slug='apo' %}{% endlanguage %} {% language 'pt-br' %} {% url 'no-prefix-translated-slug' slug='apo' %}{% endlanguage %} - """ - ) + """) self.assertEqual( tpl.render(Context({})).strip().split(), ["/vertaald/apo/", "/traduzidos/apo/"], diff --git a/tests/m2m_through_regress/tests.py b/tests/m2m_through_regress/tests.py index eae151546bd3..77a15a574bf7 100644 --- a/tests/m2m_through_regress/tests.py +++ b/tests/m2m_through_regress/tests.py @@ -113,8 +113,7 @@ def test_serialization(self): Roll - """.strip() - % pks, + """.strip() % pks, ) diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 1dba83eb8ece..851d1c371cef 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -1087,15 +1087,13 @@ def test_attach_8bit_rfc822_message_non_ascii(self): Attaching a message that uses 8bit content transfer encoding for non-ASCII characters should not raise a UnicodeEncodeError (#36119). """ - attachment = dedent( - """\ + attachment = dedent("""\ Subject: A message using 8bit CTE Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit ¡8-bit content! - """ - ).encode() + """).encode() email = EmailMessage() email.attach("attachment.eml", attachment, "message/rfc822") attachments = self.get_raw_attachments(email) diff --git a/tests/migrations/test_multidb.py b/tests/migrations/test_multidb.py index 7bf5d51454af..14667bbdc38d 100644 --- a/tests/migrations/test_multidb.py +++ b/tests/migrations/test_multidb.py @@ -112,9 +112,7 @@ def _test_run_sql(self, app_label, should_run, hints=None): sql = """ INSERT INTO {0}_pony (pink, weight) VALUES (1, 3.55); INSERT INTO {0}_pony (pink, weight) VALUES (3, 5.0); - """.format( - app_label - ) + """.format(app_label) operation = migrations.RunSQL(sql, hints=hints or {}) # Test the state alteration does nothing diff --git a/tests/model_forms/test_modelchoicefield.py b/tests/model_forms/test_modelchoicefield.py index 8765f1a6d06f..7b086fb182d0 100644 --- a/tests/model_forms/test_modelchoicefield.py +++ b/tests/model_forms/test_modelchoicefield.py @@ -402,8 +402,7 @@ class CustomModelMultipleChoiceField(forms.ModelMultipleChoiceField):
- """ - % (self.c1.pk, self.c2.pk, self.c3.pk), + """ % (self.c1.pk, self.c2.pk, self.c3.pk), ) def test_choice_value_hash(self): diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 7783b817d5cf..466674ef6488 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -1653,8 +1653,7 @@ def formfield_for_dbfield(db_field, **kwargs): -""" - % (self.c1.pk, self.c2.pk, self.c3.pk), +""" % (self.c1.pk, self.c2.pk, self.c3.pk), ) def test_basic_creation(self): @@ -3119,8 +3118,7 @@ class Meta:

- """ - % {"blue_pk": color.pk}, + """ % {"blue_pk": color.pk}, ) def test_callable_field_default(self): @@ -3157,9 +3155,7 @@ class Meta: - """.format( - today_str - ), + """.format(today_str), ) empty_data = { "title": "", diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py index eea99358047d..d6d2cacab519 100644 --- a/tests/postgres_tests/test_array.py +++ b/tests/postgres_tests/test_array.py @@ -1521,12 +1521,10 @@ def test_render_attrs(self): "array", ["val1", "val2"], attrs={"id": "foo"}, - html=( - """ + html=(""" - """ - ), + """), ) def test_value_omitted_from_data(self): diff --git a/tests/requirements/py3.txt b/tests/requirements/py3.txt index 5efe491430d7..7b60635b9252 100644 --- a/tests/requirements/py3.txt +++ b/tests/requirements/py3.txt @@ -2,7 +2,7 @@ aiosmtpd >= 1.4.5 asgiref >= 3.9.1 argon2-cffi >= 23.1.0 bcrypt >= 4.1.1 -black >= 25.12.0 +black >= 26.1.0 docutils >= 0.22 geoip2 >= 4.8.0 jinja2 >= 2.11.0 diff --git a/tests/serializers/test_deserialization.py b/tests/serializers/test_deserialization.py index b6a0818c427a..f4be93957aa0 100644 --- a/tests/serializers/test_deserialization.py +++ b/tests/serializers/test_deserialization.py @@ -144,15 +144,13 @@ def test_crafted_xml_rejected(self): nested_close = "" * depth leaf = "x" * leaf_text_len field_content = f"{nested_open}{leaf}{nested_close}" - crafted_xml = textwrap.dedent( - f""" + crafted_xml = textwrap.dedent(f""" {field_content} m - """ - ) + """) msg = "Unexpected element: 'nested'" with self.assertRaisesMessage(SuspiciousOperation, msg): diff --git a/tests/sitemaps_tests/test_http.py b/tests/sitemaps_tests/test_http.py index b62060c0c6ca..be96ff6ba317 100644 --- a/tests/sitemaps_tests/test_http.py +++ b/tests/sitemaps_tests/test_http.py @@ -51,9 +51,7 @@ def test_paged_sitemap(self): {0}/simple/sitemap-simple.xml{1}{0}/simple/sitemap-simple.xml?p=2{1} -""".format( - self.base_url, date.today() - ) +""".format(self.base_url, date.today()) self.assertXMLEqual(response.text, expected_content) @override_settings( @@ -364,9 +362,7 @@ def test_alternate_i18n_sitemap_index(self): -""".replace( - "\n", "" - ) +""".replace("\n", "") expected_content = ( f'\n' f' -""".replace( - "\n", "" - ) +""".replace("\n", "") expected_content = ( f'\n' f' -""".replace( - "\n", "" - ) +""".replace("\n", "") expected_content = ( f'\n' f'var a = "";') - 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, '
') @@ -1224,9 +1218,7 @@ def test_simple_equal_raises_message(self): - + ? ++++++++++ -""".format( - xml1=repr(xml1), xml2=repr(xml2) - ) +""".format(xml1=repr(xml1), xml2=repr(xml2)) with self.assertRaisesMessage(AssertionError, msg): self.assertXMLEqual(xml1, xml2)