diff --git a/scripts/get-translator-credits.py b/scripts/get-translator-credits.py index cb2012e390..bd4a0cfe14 100644 --- a/scripts/get-translator-credits.py +++ b/scripts/get-translator-credits.py @@ -58,7 +58,7 @@ language_names = [ ] language_names.sort() -for (language_name, locale) in language_names: +for language_name, locale in language_names: print(f"{language_name} - {locale}") # noqa: T201 print("-----") # noqa: T201 for author in sorted(authors_by_locale[locale]): diff --git a/wagtail/actions/copy_page.py b/wagtail/actions/copy_page.py index d800797244..ea9589166d 100644 --- a/wagtail/actions/copy_page.py +++ b/wagtail/actions/copy_page.py @@ -145,7 +145,6 @@ class CopyPageAction: ) # Save copied child objects and run process_child_object on them if we need to for (child_relation, old_pk), child_object in child_object_map.items(): - if self.process_child_object: self.process_child_object( specific_page, page_copy, child_relation, child_object diff --git a/wagtail/actions/create_alias.py b/wagtail/actions/create_alias.py index a054a65a31..ae942e3361 100644 --- a/wagtail/actions/create_alias.py +++ b/wagtail/actions/create_alias.py @@ -106,7 +106,6 @@ class CreatePageAliasAction: reset_translation_key, _mpnode_attrs, ): - specific_page = page.specific # FIXME: Switch to the same fields that are excluded from copy diff --git a/wagtail/actions/unpublish_page.py b/wagtail/actions/unpublish_page.py index fe296a84a8..ea31301d59 100644 --- a/wagtail/actions/unpublish_page.py +++ b/wagtail/actions/unpublish_page.py @@ -57,7 +57,6 @@ class UnpublishPageAction(UnpublishAction): super().execute(skip_permission_checks) if self.include_descendants: - for live_descendant_page in ( self.object.get_descendants() .live() diff --git a/wagtail/admin/auth.py b/wagtail/admin/auth.py index 8df0a13f71..7808eda304 100644 --- a/wagtail/admin/auth.py +++ b/wagtail/admin/auth.py @@ -127,7 +127,6 @@ def reject_request(request): def require_admin_access(view_func): def decorated_view(request, *args, **kwargs): - user = request.user if user.is_anonymous: diff --git a/wagtail/admin/forms/collections.py b/wagtail/admin/forms/collections.py index 40e1280150..ff38596190 100644 --- a/wagtail/admin/forms/collections.py +++ b/wagtail/admin/forms/collections.py @@ -297,7 +297,6 @@ class BaseGroupCollectionMemberPermissionFormSet(forms.BaseFormSet): def collection_member_permission_formset_factory( model, permission_types, template, default_prefix=None ): - permission_queryset = Permission.objects.filter( content_type__app_label=model._meta.app_label, codename__in=[ diff --git a/wagtail/admin/forms/tags.py b/wagtail/admin/forms/tags.py index 44f411cb85..c2700d4e34 100644 --- a/wagtail/admin/forms/tags.py +++ b/wagtail/admin/forms/tags.py @@ -33,7 +33,6 @@ class TagField(TaggitTagField): self.widget.free_tagging = self.free_tagging def clean(self, value): - value = super().clean(value) max_tag_length = self.tag_model.name.field.max_length diff --git a/wagtail/admin/mail.py b/wagtail/admin/mail.py index 84bbcbc40b..38ca32fbf8 100644 --- a/wagtail/admin/mail.py +++ b/wagtail/admin/mail.py @@ -97,7 +97,6 @@ def send_notification(recipient_users, notification, extra_context): connection = get_connection() with OpenedConnection(connection) as open_connection: - # Send emails sent_count = 0 for recipient in email_recipients: @@ -229,12 +228,10 @@ class EmailNotificationMixin: } def send_emails(self, template_set, context, recipients, **kwargs): - connection = get_connection() sent_count = 0 try: with OpenedConnection(connection) as open_connection: - # Send emails for recipient in recipients: # update context with this recipient diff --git a/wagtail/admin/models.py b/wagtail/admin/models.py index cb1383d236..c9e0bc8220 100644 --- a/wagtail/admin/models.py +++ b/wagtail/admin/models.py @@ -16,9 +16,7 @@ from wagtail.models import Page # management command. class Admin(Model): class Meta: - default_permissions = ( - [] - ) # don't create the default add / change / delete / view perms + default_permissions = [] # don't create the default add / change / delete / view perms permissions = [ ("access_admin", "Can access Wagtail admin"), ] diff --git a/wagtail/admin/panels/field_panel.py b/wagtail/admin/panels/field_panel.py index fa3b143516..7fd27d89b0 100644 --- a/wagtail/admin/panels/field_panel.py +++ b/wagtail/admin/panels/field_panel.py @@ -110,11 +110,10 @@ class FieldPanel(Panel): labels = dict(choices) display_values = [ str(labels.get(v, v)) # Use raw value if no match found - for v in ( + for v in + ( # Account for single AND multiple choice fields - tuple(value) - if isinstance(value, (list, tuple)) - else (value,) + tuple(value) if isinstance(value, (list, tuple)) else (value,) ) ] return ", ".join(display_values) @@ -275,7 +274,6 @@ class FieldPanel(Panel): return context def get_editable_context_data(self): - widget_described_by_ids = [] help_text_id = "%s-helptext" % self.prefix error_message_id = "%s-errors" % self.prefix diff --git a/wagtail/admin/panels/title_field_panel.py b/wagtail/admin/panels/title_field_panel.py index ac8d4c8ec3..e5298dfa9e 100644 --- a/wagtail/admin/panels/title_field_panel.py +++ b/wagtail/admin/panels/title_field_panel.py @@ -46,7 +46,6 @@ class TitleFieldPanel(FieldPanel): } class BoundPanel(FieldPanel.BoundPanel): - apply_actions = [ "focus->w-sync#check", "blur->w-sync#apply", diff --git a/wagtail/admin/templatetags/wagtailadmin_tags.py b/wagtail/admin/templatetags/wagtailadmin_tags.py index 2fcda7862a..e2a4625f80 100644 --- a/wagtail/admin/templatetags/wagtailadmin_tags.py +++ b/wagtail/admin/templatetags/wagtailadmin_tags.py @@ -253,9 +253,7 @@ def test_page_is_public(context, page): "request" ].all_page_view_restriction_paths = PageViewRestriction.objects.select_related( "page" - ).values_list( - "page__path", flat=True - ) + ).values_list("page__path", flat=True) is_private = any( page.path.startswith(restricted_path) diff --git a/wagtail/admin/tests/pages/test_bulk_actions/test_bulk_action.py b/wagtail/admin/tests/pages/test_bulk_actions/test_bulk_action.py index e827873a2f..84621f4759 100644 --- a/wagtail/admin/tests/pages/test_bulk_actions/test_bulk_action.py +++ b/wagtail/admin/tests/pages/test_bulk_actions/test_bulk_action.py @@ -6,7 +6,6 @@ from wagtail.test.utils import WagtailTestUtils class TestBulkActionDispatcher(WagtailTestUtils, TestCase): def setUp(self): - # Login self.user = self.login() diff --git a/wagtail/admin/tests/pages/test_edit_page.py b/wagtail/admin/tests/pages/test_edit_page.py index 1fee852451..db13ba8446 100644 --- a/wagtail/admin/tests/pages/test_edit_page.py +++ b/wagtail/admin/tests/pages/test_edit_page.py @@ -1856,7 +1856,7 @@ class TestPageEdit(WagtailTestUtils, TestCase): def test_override_default_action_menu_item(self): def hook_func(menu_items, request, context): - for (index, item) in enumerate(menu_items): + for index, item in enumerate(menu_items): if item.name == "action-publish": # move to top of list menu_items.pop(index) diff --git a/wagtail/admin/tests/test_edit_handlers.py b/wagtail/admin/tests/test_edit_handlers.py index 353145cca4..9074c6f999 100644 --- a/wagtail/admin/tests/test_edit_handlers.py +++ b/wagtail/admin/tests/test_edit_handlers.py @@ -1751,7 +1751,6 @@ class TestCommentPanel(WagtailTestUtils, TestCase): self.assertEqual(replies_formset.forms[0].for_user, self.commenting_user) def test_comment_form_validation(self): - form = self.EventPageForm( { "comments-TOTAL_FORMS": 2, @@ -1872,7 +1871,6 @@ class TestCommentPanel(WagtailTestUtils, TestCase): ) def test_comment_reply_form_validation(self): - form = self.EventPageForm( { "comments-TOTAL_FORMS": 1, @@ -2378,7 +2376,6 @@ class TestTitleFieldPanel(WagtailTestUtils, TestCase): self.assertEqual(attrs["data-w-sync-target-value"], "#id_cost, #id_location") def test_classname_override(self): - html = self.get_edit_handler_html( ObjectList( [TitleFieldPanel("title", classname="super-title"), FieldPanel("slug")] diff --git a/wagtail/admin/tests/test_reports_views.py b/wagtail/admin/tests/test_reports_views.py index 4caa71a0fd..dde81d68f7 100644 --- a/wagtail/admin/tests/test_reports_views.py +++ b/wagtail/admin/tests/test_reports_views.py @@ -122,7 +122,6 @@ class TestLockedPagesView(WagtailTestUtils, TestCase): self.assertRedirects(response, reverse("wagtailadmin_home")) def test_csv_export(self): - self.page = Page.objects.first() self.page.locked = True self.page.locked_by = self.user @@ -156,7 +155,6 @@ class TestLockedPagesView(WagtailTestUtils, TestCase): ) def test_xlsx_export(self): - self.page = Page.objects.first() self.page.locked = True self.page.locked_by = self.user diff --git a/wagtail/admin/tests/test_views_generic.py b/wagtail/admin/tests/test_views_generic.py index 0d62947cc1..0b5bc67e8b 100644 --- a/wagtail/admin/tests/test_views_generic.py +++ b/wagtail/admin/tests/test_views_generic.py @@ -6,7 +6,6 @@ from wagtail.test.utils import WagtailTestUtils class TestGenericIndexView(WagtailTestUtils, TestCase): - fixtures = ["test.json"] def get(self, params={}): @@ -26,7 +25,6 @@ class TestGenericIndexView(WagtailTestUtils, TestCase): class TestGenericEditView(WagtailTestUtils, TestCase): - fixtures = ["test.json"] def get(self, object_pk, params={}): @@ -63,7 +61,6 @@ class TestGenericEditView(WagtailTestUtils, TestCase): class TestGenericDeleteView(WagtailTestUtils, TestCase): - fixtures = ["test.json"] def get(self, object_pk, params={}): diff --git a/wagtail/admin/tests/ui/test_sidebar.py b/wagtail/admin/tests/ui/test_sidebar.py index ea5575bb23..e5c21bc7f0 100644 --- a/wagtail/admin/tests/ui/test_sidebar.py +++ b/wagtail/admin/tests/ui/test_sidebar.py @@ -68,7 +68,6 @@ class TestAdaptLinkMenuItem(TestCase): ) def test_adapt_with_deprecated_classnames(self): - with self.assertWarnsRegex( RemovedInWagtail70Warning, "The `classnames` kwarg for sidebar LinkMenuItem is deprecated - use `classname` instead.", diff --git a/wagtail/admin/userbar.py b/wagtail/admin/userbar.py index 2516f24acf..e1f64ea24c 100644 --- a/wagtail/admin/userbar.py +++ b/wagtail/admin/userbar.py @@ -18,7 +18,6 @@ class AdminItem(BaseItem): template = "wagtailadmin/userbar/item_admin.html" def render(self, request): - # Don't render if user doesn't have permission to access the admin area if not request.user.has_perm("wagtailadmin.access_admin"): return "" diff --git a/wagtail/admin/views/generic/permissions.py b/wagtail/admin/views/generic/permissions.py index 559e0792a6..953e23a96a 100644 --- a/wagtail/admin/views/generic/permissions.py +++ b/wagtail/admin/views/generic/permissions.py @@ -20,7 +20,6 @@ class PermissionCheckedMixin: def dispatch(self, request, *args, **kwargs): if self.permission_policy is not None: - if self.permission_required is not None: if not self.user_has_permission(self.permission_required): raise PermissionDenied diff --git a/wagtail/admin/views/home.py b/wagtail/admin/views/home.py index eae56c91fe..515123acc7 100644 --- a/wagtail/admin/views/home.py +++ b/wagtail/admin/views/home.py @@ -285,7 +285,6 @@ class RecentEditsPanel(Component): class HomeView(WagtailAdminTemplateMixin, TemplateView): - template_name = "wagtailadmin/home.html" page_title = gettext_lazy("Dashboard") diff --git a/wagtail/bin/wagtail.py b/wagtail/bin/wagtail.py index a0df1245f3..aea5340550 100644 --- a/wagtail/bin/wagtail.py +++ b/wagtail/bin/wagtail.py @@ -221,7 +221,7 @@ class UpdateModulePaths(Command): checked_file_count = 0 changed_file_count = 0 - for (dirpath, dirnames, filenames) in os.walk(root_path): + for dirpath, dirnames, filenames in os.walk(root_path): dirpath_with_slash = os.path.abspath(dirpath) + os.sep if any( dirpath_with_slash.startswith(ignored_dir) diff --git a/wagtail/blocks/field_block.py b/wagtail/blocks/field_block.py index 66edaf4dd1..876b14b34a 100644 --- a/wagtail/blocks/field_block.py +++ b/wagtail/blocks/field_block.py @@ -491,7 +491,6 @@ class BaseChoiceBlock(FieldBlock): validators=(), **kwargs, ): - self._required = required self._default = default self.search_index = search_index diff --git a/wagtail/blocks/struct_block.py b/wagtail/blocks/struct_block.py index 7f4ce05e2f..fb83998b32 100644 --- a/wagtail/blocks/struct_block.py +++ b/wagtail/blocks/struct_block.py @@ -155,9 +155,7 @@ class BaseStructBlock(Block): ) def clean(self, value): - result = ( - [] - ) # build up a list of (name, value) tuples to be passed to the StructValue constructor + result = [] # build up a list of (name, value) tuples to be passed to the StructValue constructor errors = {} for name, val in value.items(): try: @@ -180,7 +178,7 @@ class BaseStructBlock(Block): child_block.to_python(value[name]) if name in value else child_block.get_default() - ) + ), # NB the result of get_default is NOT passed through to_python, as it's expected # to be in the block's native type already ) diff --git a/wagtail/contrib/forms/tests/test_models.py b/wagtail/contrib/forms/tests/test_models.py index 05a309c6ef..f76446d3d1 100644 --- a/wagtail/contrib/forms/tests/test_models.py +++ b/wagtail/contrib/forms/tests/test_models.py @@ -567,7 +567,6 @@ class TestFormWithRedirect(TestCase): class TestFormPageWithCustomFormBuilder(WagtailTestUtils, TestCase): def setUp(self): - home_page = Page.objects.get(url_path="/home/") form_page = home_page.add_child( instance=FormPageWithCustomFormBuilder( diff --git a/wagtail/contrib/forms/tests/test_views.py b/wagtail/contrib/forms/tests/test_views.py index c191643925..c72739b3b2 100644 --- a/wagtail/contrib/forms/tests/test_views.py +++ b/wagtail/contrib/forms/tests/test_views.py @@ -1602,7 +1602,6 @@ class TestDuplicateFormFieldLabels(WagtailTestUtils, TestCase): fixtures = ["test.json"] def setUp(self): - self.login(username="superuser", password="password") # Find root page self.root_page = Page.objects.get(id=2) @@ -1759,7 +1758,6 @@ class TestDuplicateFormFieldLabels(WagtailTestUtils, TestCase): class TestPreview(WagtailTestUtils, TestCase): - post_data = { "title": "Form page!", "content": "Some content", diff --git a/wagtail/contrib/frontend_cache/backends.py b/wagtail/contrib/frontend_cache/backends.py index dd3eac7897..e4ee527db5 100644 --- a/wagtail/contrib/frontend_cache/backends.py +++ b/wagtail/contrib/frontend_cache/backends.py @@ -342,7 +342,6 @@ class AzureBaseBackend(BaseBackend): class AzureFrontDoorBackend(AzureBaseBackend): def __init__(self, params): - super().__init__(params) try: self._front_door_name = params.pop("FRONT_DOOR_NAME") @@ -372,7 +371,6 @@ class AzureFrontDoorBackend(AzureBaseBackend): class AzureCdnBackend(AzureBaseBackend): def __init__(self, params): - super().__init__(params) try: self._cdn_profile_name = params.pop("CDN_PROFILE_NAME") diff --git a/wagtail/contrib/frontend_cache/tests.py b/wagtail/contrib/frontend_cache/tests.py index 033f95b68d..5258b90acb 100644 --- a/wagtail/contrib/frontend_cache/tests.py +++ b/wagtail/contrib/frontend_cache/tests.py @@ -422,7 +422,6 @@ class MockCloudflareBackend(CloudflareBackend): } ) class TestCachePurgingFunctions(TestCase): - fixtures = ["test.json"] def setUp(self): @@ -496,7 +495,6 @@ class TestCloudflareCachePurgingFunctions(TestCase): } ) class TestCachePurgingSignals(TestCase): - fixtures = ["test.json"] def setUp(self): diff --git a/wagtail/contrib/redirects/signal_handlers.py b/wagtail/contrib/redirects/signal_handlers.py index 7ea618e284..e520b8de59 100644 --- a/wagtail/contrib/redirects/signal_handlers.py +++ b/wagtail/contrib/redirects/signal_handlers.py @@ -93,7 +93,6 @@ def _page_urls_for_sites( ) -> Set[Tuple[Site, str, str]]: urls = set() for site in sites: - # use a `HttpRequest` to influence the return value request = get_dummy_request(site=site) # reuse cached site root paths if available diff --git a/wagtail/contrib/redirects/tests/test_signal_handlers.py b/wagtail/contrib/redirects/tests/test_signal_handlers.py index e461fc48d9..dc3b3e6626 100644 --- a/wagtail/contrib/redirects/tests/test_signal_handlers.py +++ b/wagtail/contrib/redirects/tests/test_signal_handlers.py @@ -167,7 +167,6 @@ class TestAutocreateRedirects(WagtailTestUtils, TestCase): ) def test_no_redirects_created_when_pages_are_moved_to_a_different_site(self): - # Add a new home page homepage_2 = Page( title="Second home", diff --git a/wagtail/contrib/settings/tests/site_specific/test_model.py b/wagtail/contrib/settings/tests/site_specific/test_model.py index 98eef08b89..e19a80d757 100644 --- a/wagtail/contrib/settings/tests/site_specific/test_model.py +++ b/wagtail/contrib/settings/tests/site_specific/test_model.py @@ -35,7 +35,6 @@ class SettingModelTestCase(SiteSettingsTestMixin, TestCase): # even when the requests are for the same site for i, request in enumerate([self.get_request(), self.get_request()], 1): with self.subTest(attempt=i): - # force site query beforehand Site.find_for_request(request) @@ -138,7 +137,6 @@ class SettingModelTestCase(SiteSettingsTestMixin, TestCase): ("privacy_policy_page", "http://other/"), ): with self.subTest(page_fk_field=page_fk_field): - with self.assertNumQueries(1): # because results are cached, only the first # request for a URL will trigger a query to @@ -174,7 +172,6 @@ class SettingModelTestCase(SiteSettingsTestMixin, TestCase): ("privacy_policy_page", "http://other/"), ): with self.subTest(page_fk_field=page_fk_field): - # only the first request for each URL will trigger queries. # 2 are triggered instead of 1 here, because tests use the # database cache backed, and the cache is queried each time @@ -182,7 +179,6 @@ class SettingModelTestCase(SiteSettingsTestMixin, TestCase): # store them on) with self.assertNumQueries(2): - self.assertEqual( settings.get_page_url(page_fk_field), expected_result ) diff --git a/wagtail/contrib/sitemaps/sitemap_generator.py b/wagtail/contrib/sitemaps/sitemap_generator.py index d7960288a3..b4c33005b8 100644 --- a/wagtail/contrib/sitemaps/sitemap_generator.py +++ b/wagtail/contrib/sitemaps/sitemap_generator.py @@ -42,7 +42,6 @@ class Sitemap(DjangoSitemap): last_mods = set() for item in self.paginator.page(page).object_list.iterator(): - url_info_items = item.get_sitemap_urls(self.request) for url_info in url_info_items: diff --git a/wagtail/documents/views/serve.py b/wagtail/documents/views/serve.py index 4844d5a662..8782948e98 100644 --- a/wagtail/documents/views/serve.py +++ b/wagtail/documents/views/serve.py @@ -77,7 +77,6 @@ def serve(request, document_id, document_filename): return redirect(direct_url) if local_path: - # Use wagtail.utils.sendfile to serve the file; # this provides support for mimetypes, if-modified-since and django-sendfile backends @@ -93,7 +92,6 @@ def serve(request, document_id, document_filename): return sendfile(request, local_path, **sendfile_opts) else: - # We are using a storage backend which does not expose filesystem paths # (e.g. storages.backends.s3boto.S3BotoStorage) AND the developer has not allowed # redirecting to the file url directly. diff --git a/wagtail/fields.py b/wagtail/fields.py index 439c0d673c..c8ed6196b4 100644 --- a/wagtail/fields.py +++ b/wagtail/fields.py @@ -41,7 +41,7 @@ class RichTextField(models.TextField): field = super().formfield(**defaults) # replace any MaxLengthValidators with RichTextMaxLengthValidators to ignore tags - for (i, validator) in enumerate(field.validators): + for i, validator in enumerate(field.validators): if isinstance(validator, MaxLengthValidator): field.validators[i] = RichTextMaxLengthValidator( validator.limit_value, message=validator.message @@ -244,7 +244,6 @@ class StreamField(models.Field): return self.get_prep_value(value) def get_searchable_content(self, value): - return self.stream_block.get_searchable_content(value) def extract_references(self, value): diff --git a/wagtail/images/models.py b/wagtail/images/models.py index a670401947..8d420ee082 100644 --- a/wagtail/images/models.py +++ b/wagtail/images/models.py @@ -939,7 +939,6 @@ class Filter: def run(self, image: AbstractImage, output: BytesIO, source: File = None): with self.get_willow_image(image, source) as willow: - original_format = willow.format_name # Fix orientation of image diff --git a/wagtail/images/tests/test_admin_views.py b/wagtail/images/tests/test_admin_views.py index 66dca2c5e9..833ac7b11d 100644 --- a/wagtail/images/tests/test_admin_views.py +++ b/wagtail/images/tests/test_admin_views.py @@ -740,7 +740,6 @@ class TestImageAddView(WagtailTestUtils, TestCase): self.assertEqual(image.collection, evil_plans_collection) def test_add_with_selected_collection(self): - root_collection = Collection.get_first_root_node() collection = root_collection.add_child(name="Travel pics") diff --git a/wagtail/images/tests/test_shortcuts.py b/wagtail/images/tests/test_shortcuts.py index 7ec1b4ab01..b323d53b59 100644 --- a/wagtail/images/tests/test_shortcuts.py +++ b/wagtail/images/tests/test_shortcuts.py @@ -10,7 +10,6 @@ from .utils import Image, get_test_image_file class TestShortcuts(TestCase): - fixtures = ["test.json"] def test_fallback_to_not_found(self): diff --git a/wagtail/images/views/images.py b/wagtail/images/views/images.py index 7478d2b527..009da00f28 100644 --- a/wagtail/images/views/images.py +++ b/wagtail/images/views/images.py @@ -116,7 +116,7 @@ class BaseListingView(TemplateView): if self.current_tag: try: images = images.filter(tags__name=self.current_tag) - except (AttributeError): + except AttributeError: self.current_tag = None entries_per_page = self.get_num_entries_per_page() diff --git a/wagtail/management/commands/purge_embeds.py b/wagtail/management/commands/purge_embeds.py index 550eaa5502..f52635a359 100644 --- a/wagtail/management/commands/purge_embeds.py +++ b/wagtail/management/commands/purge_embeds.py @@ -7,7 +7,6 @@ class Command(BaseCommand): help = "Deletes all of the Embed model objects" def handle(self, *args, **options): - embeds = Embed.objects.all() deleted_embeds_count = embeds.delete()[0] diff --git a/wagtail/management/commands/set_url_paths.py b/wagtail/management/commands/set_url_paths.py index 4ffceb543e..de692b21e6 100644 --- a/wagtail/management/commands/set_url_paths.py +++ b/wagtail/management/commands/set_url_paths.py @@ -4,7 +4,6 @@ from wagtail.models import Page class Command(BaseCommand): - help = "Resets url_path fields on each page recursively" def set_subtree(self, root, parent=None): diff --git a/wagtail/models/audit_log.py b/wagtail/models/audit_log.py index c5d068e0b7..8aa43970af 100644 --- a/wagtail/models/audit_log.py +++ b/wagtail/models/audit_log.py @@ -69,9 +69,7 @@ class LogEntryQuerySet(models.QuerySet): for log_entry in log_entries: ids_by_content_type[log_entry.content_type_id].append(log_entry.object_id) - instances_by_id = ( - {} - ) # lookup of (content_type_id, stringified_object_id) to instance + instances_by_id = {} # lookup of (content_type_id, stringified_object_id) to instance for content_type_id, object_ids in ids_by_content_type.items(): try: content_type = ContentType.objects.get_for_id(content_type_id) diff --git a/wagtail/models/reference_index.py b/wagtail/models/reference_index.py index 297d4e279b..81a495c08e 100644 --- a/wagtail/models/reference_index.py +++ b/wagtail/models/reference_index.py @@ -336,9 +336,12 @@ class ReferenceIndex(models.Model): # select the appropriate superclass if necessary, before converting back to a # content type. model = ContentType.objects.get_for_id(ct_value).model_class() - yield cls._get_base_content_type(model).id, str( - fk_value - ), field.name, field.name + yield ( + cls._get_base_content_type(model).id, + str(fk_value), + field.name, + field.name, + ) continue @@ -347,9 +350,12 @@ class ReferenceIndex(models.Model): value = field.value_from_object(object) if value is not None: - yield cls._get_base_content_type(field.related_model).id, str( - value - ), field.name, field.name + yield ( + cls._get_base_content_type(field.related_model).id, + str(value), + field.name, + field.name, + ) if hasattr(field, "extract_references"): value = field.value_from_object(object) @@ -483,7 +489,7 @@ class ReferenceIndex(models.Model): deleted_reference_ids = [] # Look at the reference record and the supporting content_type / id for each existing # reference in the database - for (reference_data, (content_type_id, id)) in existing_references.items(): + for reference_data, (content_type_id, id) in existing_references.items(): if reference_data in references: # Do not delete this reference, as it is still present in the new set continue diff --git a/wagtail/query.py b/wagtail/query.py index 0f3b48c56e..1382da2aad 100644 --- a/wagtail/query.py +++ b/wagtail/query.py @@ -520,7 +520,6 @@ class SpecificIterable(BaseIterable): # Gather items in batches to reduce peak memory usage for values in self._get_chunks(values_qs): - annotations_by_pk = defaultdict(list) if annotation_aliases: # Extract annotation results keyed by pk so we can reapply to fetched items. diff --git a/wagtail/search/backends/database/mysql/mysql.py b/wagtail/search/backends/database/mysql/mysql.py index ca8dbefa4f..e8bd4bfe3b 100644 --- a/wagtail/search/backends/database/mysql/mysql.py +++ b/wagtail/search/backends/database/mysql/mysql.py @@ -491,9 +491,7 @@ class MySQLSearchQueryCompiler(BaseSearchQueryCompiler): ) if not negated: index_entries = index_entries.filter(match_expression) - if ( - self.order_by_relevance - ): # Only applies to the case where the outermost query is not a Not(), because if it is, the relevance score is always 0 (anything that matches is excluded from the results). + if self.order_by_relevance: # Only applies to the case where the outermost query is not a Not(), because if it is, the relevance score is always 0 (anything that matches is excluded from the results). index_entries = index_entries.order_by(score_expression.desc()) else: index_entries = index_entries.exclude(match_expression) diff --git a/wagtail/search/backends/database/mysql/query.py b/wagtail/search/backends/database/mysql/query.py index 13c5784b01..e3259b1637 100644 --- a/wagtail/search/backends/database/mysql/query.py +++ b/wagtail/search/backends/database/mysql/query.py @@ -15,8 +15,7 @@ class LexemeCombinable(Expression): def _combine(self, other, connector, reversed, node=None): if not isinstance(other, LexemeCombinable): raise TypeError( - "Lexeme can only be combined with other Lexemes, " - "got {}.".format(type(other)) + f"Lexeme can only be combined with other Lexemes, got {type(other)}." ) if reversed: return CombinedLexeme(other, connector, self) @@ -235,10 +234,13 @@ class MatchExpression(Expression): ) -> None: super().__init__(output_field=output_field) self.query = query - self.columns = columns or [ - "title", - "body", - ] # We need to provide a default list of columns if the user doesn't specify one. We have a joint index for for 'title' and 'body' (see wagtail.search.migrations.0006_customise_indexentry), so we'll pick that one. + self.columns = ( + columns + or [ + "title", + "body", + ] + ) # We need to provide a default list of columns if the user doesn't specify one. We have a joint index for for 'title' and 'body' (see wagtail.search.migrations.0006_customise_indexentry), so we'll pick that one. def as_sql(self, compiler, connection): compiled_query = compiler.compile(self.query) # Compile the query to a string diff --git a/wagtail/search/backends/database/postgres/query.py b/wagtail/search/backends/database/postgres/query.py index 67c63746f0..d6e9a8edb3 100644 --- a/wagtail/search/backends/database/postgres/query.py +++ b/wagtail/search/backends/database/postgres/query.py @@ -9,8 +9,7 @@ class LexemeCombinable(Expression): def _combine(self, other, connector, reversed, node=None): if not isinstance(other, LexemeCombinable): raise TypeError( - "Lexeme can only be combined with other Lexemes, " - "got {}.".format(type(other)) + f"Lexeme can only be combined with other Lexemes, got {type(other)}." ) if reversed: return CombinedLexeme(other, connector, self) diff --git a/wagtail/search/backends/database/sqlite/query.py b/wagtail/search/backends/database/sqlite/query.py index ee2b1d1121..2fd97f4c35 100644 --- a/wagtail/search/backends/database/sqlite/query.py +++ b/wagtail/search/backends/database/sqlite/query.py @@ -34,8 +34,7 @@ class LexemeCombinable(Expression): def _combine(self, other, connector, reversed, node=None): if not isinstance(other, LexemeCombinable): raise TypeError( - "Lexeme can only be combined with other Lexemes, " - "got {}.".format(type(other)) + f"Lexeme can only be combined with other Lexemes, got {type(other)}." ) if reversed: return CombinedLexeme(other, connector, self) @@ -248,9 +247,7 @@ def normalize(search_query: SearchQuery) -> Tuple[SearchQuery]: ): # If there are no negated subqueries, return an And(), now without the redundant MatchAll subqueries. return And(not_negated_subqueries) - for ( - subquery - ) in ( + for subquery in ( negated_subqueries ): # If there's a negated MatchAll subquery, then nothing will get matched. if isinstance(subquery, MatchAll): @@ -272,9 +269,7 @@ def normalize(search_query: SearchQuery) -> Tuple[SearchQuery]: ): # If there are no negated subqueries, return an Or(). return Or(normalized_subqueries) - for ( - subquery - ) in ( + for subquery in ( negated_subqueries ): # If there's a MatchAll subquery, then anything will get matched. if isinstance(subquery, MatchAll): diff --git a/wagtail/search/backends/database/sqlite/sqlite.py b/wagtail/search/backends/database/sqlite/sqlite.py index c5d0d1c209..3ad281a66d 100644 --- a/wagtail/search/backends/database/sqlite/sqlite.py +++ b/wagtail/search/backends/database/sqlite/sqlite.py @@ -471,7 +471,6 @@ class SQLiteSearchQueryCompiler(BaseSearchQueryCompiler): return self.get_index_vectors() def _build_rank_expression(self, vectors, config): - # TODO: Come up with my own expression class that compiles down to bm25 rank_expressions = [ @@ -508,7 +507,9 @@ class SQLiteSearchQueryCompiler(BaseSearchQueryCompiler): vectors = self.get_search_vectors() rank_expression = self._build_rank_expression(vectors, config) - combined_vector = vectors[0][ + combined_vector = vectors[ + 0 + ][ 0 ] # We create a combined vector for the search results queryset. We start with the first vector and build from there. for vector, boost in vectors[1:]: diff --git a/wagtail/search/tests/test_queries.py b/wagtail/search/tests/test_queries.py index f436c67db8..10063aaddc 100644 --- a/wagtail/search/tests/test_queries.py +++ b/wagtail/search/tests/test_queries.py @@ -303,6 +303,6 @@ class TestBalancedReduce(SimpleTestCase): repr( balanced_reduce(CombinedNode, ["A", "B", "C", "D", "E", "F", "G", "H"]) ), - "(((A B) (C D)) ((E F) (G H)))" + "(((A B) (C D)) ((E F) (G H)))", # Note: functools.reduce will return '(((((((A B) C) D) E) F) G) H)' ) diff --git a/wagtail/snippets/tests/test_snippets.py b/wagtail/snippets/tests/test_snippets.py index 6dedef0192..87696be8b2 100644 --- a/wagtail/snippets/tests/test_snippets.py +++ b/wagtail/snippets/tests/test_snippets.py @@ -4980,7 +4980,6 @@ class TestSnippetChosen(WagtailTestUtils, TestCase): self.assertEqual(response_json["step"], "chosen") def test_choose_a_non_existing_page(self): - response = self.get(999999) self.assertEqual(response.status_code, 404) @@ -5695,7 +5694,6 @@ class TestPanelConfigurationChecks(WagtailTestUtils, TestCase): self.get_checks_result = get_checks_result def test_model_with_single_tabbed_panel_only(self): - StandardSnippet.content_panels = [FieldPanel("text")] warning = checks.Warning( diff --git a/wagtail/test/demosite/models.py b/wagtail/test/demosite/models.py index 3e590a0e02..5cecc83045 100644 --- a/wagtail/test/demosite/models.py +++ b/wagtail/test/demosite/models.py @@ -685,7 +685,6 @@ class FormField(AbstractFormField): class FormPage(AbstractForm): - page_ptr = models.OneToOneField( Page, parent_link=True, related_name="+", on_delete=models.CASCADE ) diff --git a/wagtail/test/testapp/views.py b/wagtail/test/testapp/views.py index 02cc54332f..0014b92ed5 100644 --- a/wagtail/test/testapp/views.py +++ b/wagtail/test/testapp/views.py @@ -58,7 +58,6 @@ class CustomSubmissionsListView(SubmissionsListView): class TestIndexView(IndexView): - model = ModelWithStringTypePrimaryKey index_url_name = "testapp_generic_index" template_name = "tests/generic_view_templates/index.html" @@ -73,7 +72,6 @@ class CustomModelEditForm(forms.ModelForm): class TestEditView(EditView): - model = ModelWithStringTypePrimaryKey context_object_name = "test_object" template_name = "tests/generic_view_templates/edit.html" @@ -87,7 +85,6 @@ class TestEditView(EditView): class TestDeleteView(DeleteView): - model = ModelWithStringTypePrimaryKey context_object_name = "test_object" template_name = "tests/generic_view_templates/delete.html" diff --git a/wagtail/test/utils/wagtail_factories/factories.py b/wagtail/test/utils/wagtail_factories/factories.py index a4fde202b4..0904bf7409 100644 --- a/wagtail/test/utils/wagtail_factories/factories.py +++ b/wagtail/test/utils/wagtail_factories/factories.py @@ -21,7 +21,6 @@ logger = logging.getLogger(__file__) class ParentNodeFactory(ParameteredAttribute): - EXTEND_CONTAINERS = True FORCE_SEQUENCE = False UNROLL_CONTEXT_BEFORE_EVALUATION = False @@ -43,7 +42,6 @@ class ParentNodeFactory(ParameteredAttribute): class MP_NodeFactory(DjangoModelFactory): - parent = ParentNodeFactory() @classmethod diff --git a/wagtail/tests/streamfield_migrations/test_bad_data.py b/wagtail/tests/streamfield_migrations/test_bad_data.py index 55d9d6fe64..68c49d3870 100644 --- a/wagtail/tests/streamfield_migrations/test_bad_data.py +++ b/wagtail/tests/streamfield_migrations/test_bad_data.py @@ -152,7 +152,6 @@ class TestExceptionRaisedForInstance(BadDataMigrationTestCase): self.append_invalid_instance_data() def test_migrate(self): - with self.assertRaisesMessage( InvalidBlockDefError, "Invalid block def in {} object ({})".format( diff --git a/wagtail/tests/test_page_model.py b/wagtail/tests/test_page_model.py index 3d8e0e2058..6750a0322e 100644 --- a/wagtail/tests/test_page_model.py +++ b/wagtail/tests/test_page_model.py @@ -1385,7 +1385,6 @@ class TestCopyPage(TestCase): ) def test_copy_page_with_process_child_object_supplied(self): - # We'll provide this when copying and test that it gets called twice: # Once for the single speaker, and another for the single advert_placement modify_child = Mock() diff --git a/wagtail/tests/test_page_queryset.py b/wagtail/tests/test_page_queryset.py index 6071419f06..c000f2bbd9 100644 --- a/wagtail/tests/test_page_queryset.py +++ b/wagtail/tests/test_page_queryset.py @@ -892,7 +892,6 @@ class TestSpecificQuery(WagtailTestUtils, TestCase): ) def test_specific_query_with_annotations_performs_no_additional_queries(self): - with self.assertNumQueries(5): pages = list(self.live_pages) diff --git a/wagtail/tests/test_permission_policies.py b/wagtail/tests/test_permission_policies.py index 080c029898..cbbd189d34 100644 --- a/wagtail/tests/test_permission_policies.py +++ b/wagtail/tests/test_permission_policies.py @@ -30,7 +30,7 @@ class PermissionPolicyTestUtils: user = test_case[0] expected_results = zip(actions, test_case[1:]) - for (action, expected_result) in expected_results: + for action, expected_result in expected_results: if expected_result: self.assertTrue( self.policy.user_has_permission(user, action), @@ -58,7 +58,7 @@ class PermissionPolicyTestUtils: user = test_case[0] expected_results = zip(actions, test_case[1:]) - for (action, expected_result) in expected_results: + for action, expected_result in expected_results: if expected_result: self.assertTrue( self.policy.user_has_permission_for_instance( diff --git a/wagtail/tests/test_utils.py b/wagtail/tests/test_utils.py index ee3da961fd..91a1a14d3c 100644 --- a/wagtail/tests/test_utils.py +++ b/wagtail/tests/test_utils.py @@ -38,7 +38,7 @@ class TestCamelCaseToUnderscore(TestCase): ("longValueWithVarious subStrings", "long_value_with_various sub_strings"), ] - for (original, expected_result) in test_cases: + for original, expected_result in test_cases: self.assertEqual(camelcase_to_underscore(original), expected_result) @@ -59,7 +59,7 @@ class TestStringToAscii(TestCase): ("〔山脈〕", "[ShanMai]"), ] - for (original, expected_result) in test_cases: + for original, expected_result in test_cases: self.assertEqual(string_to_ascii(original), expected_result) @@ -78,7 +78,7 @@ class TestCautiousSlugify(TestCase): ("Hello☃world", "helloworld"), ] - for (original, expected_result) in test_cases: + for original, expected_result in test_cases: self.assertEqual(slugify(original), expected_result) self.assertEqual(cautious_slugify(original), expected_result) @@ -89,7 +89,7 @@ class TestCautiousSlugify(TestCase): ("〔山脈〕", "u5c71u8108"), ] - for (original, expected_result) in test_cases: + for original, expected_result in test_cases: self.assertEqual(cautious_slugify(original), expected_result) @@ -118,7 +118,7 @@ class TestSafeSnakeCase(TestCase): ), ] - for (original, expected_result) in test_cases: + for original, expected_result in test_cases: self.assertEqual(safe_snake_case(original), expected_result) def test_strings_with__non_latin_chars(self): @@ -127,7 +127,7 @@ class TestSafeSnakeCase(TestCase): ("Сп орт!", "u0421u043f_u043eu0440u0442"), ] - for (original, expected_result) in test_cases: + for original, expected_result in test_cases: self.assertEqual(safe_snake_case(original), expected_result) diff --git a/wagtail/utils/setup.py b/wagtail/utils/setup.py index f22e707635..b9e000f7e7 100644 --- a/wagtail/utils/setup.py +++ b/wagtail/utils/setup.py @@ -33,7 +33,7 @@ class assets_mixin: try: package = json.loads(input_file.read().decode("utf-8")) - except (ValueError) as e: + except ValueError as e: print("Unable to read " + path + " " + e) # noqa: T201 raise SystemExit(1) @@ -42,7 +42,7 @@ class assets_mixin: try: with open(path, "w", encoding="utf-8") as f: f.write(str(json.dumps(package, indent=2, ensure_ascii=False))) - except (OSError) as e: + except OSError as e: print( # noqa: T201 "Error setting the version for front-end assets: " + str(e) ) @@ -71,7 +71,6 @@ class sdist(base_sdist, assets_mixin): class check_bdist_egg(bdist_egg): - # If this file does not exist, warn the user to compile the assets sentinel_dir = "wagtail/wagtailadmin/static/"