Skip to content

Commit

Permalink
Apply suggested rewrites from pyupgrade for Python 3.9 and up
Browse files Browse the repository at this point in the history
```
git ls-files --others --cached --exclude-standard -- '*.py' | xargs pyupgrade --py39-plus
```
  • Loading branch information
gasman committed Jul 23, 2024
1 parent 4ad2527 commit 80b1ebe
Show file tree
Hide file tree
Showing 27 changed files with 91 additions and 102 deletions.
6 changes: 3 additions & 3 deletions wagtail/actions/publish_revision.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import logging
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING

from django.conf import settings
from django.core.exceptions import PermissionDenied
Expand Down Expand Up @@ -47,7 +47,7 @@ def __init__(
user=None,
changed: bool = True,
log_action: bool = True,
previous_revision: Optional[Revision] = None,
previous_revision: Revision | None = None,
):
self.revision = revision
self.object = self.revision.as_object()
Expand Down Expand Up @@ -107,7 +107,7 @@ def _publish_revision(
user,
changed,
log_action: bool,
previous_revision: Optional[Revision] = None,
previous_revision: Revision | None = None,
):
from wagtail.models import Revision

Expand Down
2 changes: 1 addition & 1 deletion wagtail/admin/panels/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def extract_panel_definitions_from_model_class(model, exclude=None):
return panels


@functools.lru_cache(maxsize=None)
@functools.cache
def get_edit_handler(model):
"""
Get the panel to use in the Wagtail admin when editing this model.
Expand Down
5 changes: 3 additions & 2 deletions wagtail/admin/tests/test_edit_handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections.abc import Mapping
from datetime import date, datetime, timezone
from functools import wraps
from typing import Any, List, Mapping, Optional
from typing import Any, Optional
from unittest import mock

from django import forms
Expand Down Expand Up @@ -846,7 +847,7 @@ def setUp(self):
def _get_form(
self,
data: Optional[Mapping[str, Any]] = None,
fields: Optional[List[str]] = None,
fields: Optional[list[str]] = None,
) -> WagtailAdminPageForm:
cls = get_form_for_model(
EventPage,
Expand Down
7 changes: 4 additions & 3 deletions wagtail/admin/ui/sidebar.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, List, Mapping
from collections.abc import Mapping
from typing import Any
from warnings import warn

from django import forms
Expand Down Expand Up @@ -152,7 +153,7 @@ def __init__(
self,
name: str,
label: str,
menu_items: List[MenuItem],
menu_items: list[MenuItem],
icon_name: str = "",
classname: str = "",
classnames: str = "",
Expand Down Expand Up @@ -262,7 +263,7 @@ def js_args(self):
@adapter("wagtail.sidebar.MainMenuModule", base=BaseSidebarAdapter)
class MainMenuModule:
def __init__(
self, menu_items: List[MenuItem], account_menu_items: List[MenuItem], user
self, menu_items: list[MenuItem], account_menu_items: list[MenuItem], user
):
self.menu_items = menu_items
self.account_menu_items = account_menu_items
Expand Down
2 changes: 1 addition & 1 deletion wagtail/admin/views/generic/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def active_filters(self):
ActiveFilter(
bound_field.auto_id,
filter_def.label,
"%s - %s" % (start_date_display, end_date_display),
f"{start_date_display} - {end_date_display}",
self.get_url_without_filter_param(
[
widget.suffixed(field_name, suffix)
Expand Down
3 changes: 2 additions & 1 deletion wagtail/admin/views/home.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Mapping, Union
from collections.abc import Mapping
from typing import Any, Union

from django.conf import settings
from django.contrib.auth import get_user_model
Expand Down
6 changes: 3 additions & 3 deletions wagtail/admin/views/pages/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict
from typing import Any

from django.conf import settings
from django.contrib.contenttypes.models import ContentType
Expand Down Expand Up @@ -165,7 +165,7 @@ def get_table_kwargs(self):
kwargs["actions_next_url"] = self.get_index_url()
return kwargs

def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
context.update(
{
Expand All @@ -182,7 +182,7 @@ def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
class SearchView(BaseSearchView):
template_name = "wagtailadmin/pages/search.html"

def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
context["search_form"] = SearchForm(self.request.GET)
return context
Expand Down
4 changes: 2 additions & 2 deletions wagtail/admin/views/pages/usage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict
from typing import Any

from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import PermissionDenied
Expand Down Expand Up @@ -68,7 +68,7 @@ def get_index_url(self):
],
)

def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
context = super().get_context_data(**kwargs)
context["page_class"] = self.page_class
return context
Expand Down
6 changes: 3 additions & 3 deletions wagtail/contrib/redirects/signal_handlers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Iterable, Set, Tuple
from collections.abc import Iterable

from django.conf import settings
from django.db.models import Q
Expand Down Expand Up @@ -89,8 +89,8 @@ def autocreate_redirects_on_page_move(


def _page_urls_for_sites(
page: Page, sites: Tuple[Site], cache_target: Page
) -> Set[Tuple[Site, str, str]]:
page: Page, sites: tuple[Site], cache_target: Page
) -> set[tuple[Site, str, str]]:
urls = set()
for site in sites:
# use a `HttpRequest` to influence the return value
Expand Down
3 changes: 1 addition & 2 deletions wagtail/contrib/redirects/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
from typing import List

from django.core.exceptions import PermissionDenied, SuspiciousOperation
from django.db import transaction
Expand Down Expand Up @@ -123,7 +122,7 @@ def get_base_queryset(self):
return super().get_base_queryset().select_related("redirect_page", "site")

@cached_property
def header_more_buttons(self) -> List[Button]:
def header_more_buttons(self) -> list[Button]:
buttons = super().header_more_buttons.copy()
buttons.append(
Button(
Expand Down
4 changes: 1 addition & 3 deletions wagtail/contrib/simple_translation/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

from django.conf import settings
from django.contrib.admin.utils import quote
from django.contrib.auth.models import Permission
Expand Down Expand Up @@ -118,7 +116,7 @@ def register_snippet_listing_buttons(snippet, user, next_url=None):


@hooks.register("construct_translated_pages_to_cascade_actions")
def construct_translated_pages_to_cascade_actions(pages: List[Page], action: str):
def construct_translated_pages_to_cascade_actions(pages: list[Page], action: str):
if not getattr(settings, "WAGTAILSIMPLETRANSLATION_SYNC_PAGE_TREE", False):
return

Expand Down
7 changes: 4 additions & 3 deletions wagtail/coreutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import logging
import re
import unicodedata
from collections.abc import Iterable
from hashlib import md5
from typing import TYPE_CHECKING, Any, Dict, Iterable, Union
from typing import TYPE_CHECKING, Any, Union
from warnings import warn

from anyascii import anyascii
Expand Down Expand Up @@ -256,7 +257,7 @@ def find_available_slug(parent, requested_slug, ignore_page_id=None):
return slug


@functools.lru_cache(maxsize=None)
@functools.cache
def get_content_languages():
"""
Cache of settings.WAGTAIL_CONTENT_LANGUAGES in a dictionary for easy lookups by key.
Expand Down Expand Up @@ -545,7 +546,7 @@ def add(self, *, instance: Model = None, **kwargs) -> None:
if self.max_size and len(self.items) == self.max_size:
self.process()

def extend(self, iterable: Iterable[Union[Model, Dict[str, Any]]]) -> None:
def extend(self, iterable: Iterable[Union[Model, dict[str, Any]]]) -> None:
for value in iterable:
if isinstance(value, self.model):
self.add(instance=value)
Expand Down
4 changes: 1 addition & 3 deletions wagtail/documents/rich_text/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

from django.utils.html import escape

from wagtail.documents import get_document_model
Expand All @@ -20,7 +18,7 @@ def expand_db_attributes(cls, attrs: dict) -> str:
return cls.expand_db_attributes_many([attrs])[0]

@classmethod
def expand_db_attributes_many(cls, attrs_list: List[dict]) -> List[str]:
def expand_db_attributes_many(cls, attrs_list: list[dict]) -> list[str]:
return [
'<a href="%s">' % escape(doc.url) if doc else "<a>"
for doc in cls.get_many(attrs_list)
Expand Down
Loading

0 comments on commit 80b1ebe

Please sign in to comment.