diff --git a/docs/conf.py b/docs/conf.py index 16a46309..110a0435 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,7 +28,7 @@ django.setup() # package data -about: t.Dict[str, str] = {} +about: dict[str, str] = {} with (src_root / "django_docutils" / "__about__.py").open() as fp: exec(fp.read(), about) @@ -76,8 +76,8 @@ html_css_files = ["css/custom.css"] html_extra_path = ["manifest.json"] html_theme = "furo" -html_theme_path: t.List[str] = [] -html_theme_options: t.Dict[str, t.Union[str, t.List[t.Dict[str, str]]]] = { +html_theme_path: list[str] = [] +html_theme_options: dict[str, t.Union[str, list[dict[str, str]]]] = { "light_logo": "img/icons/logo.svg", "dark_logo": "img/icons/logo-dark.svg", "footer_icons": [ @@ -147,7 +147,7 @@ } -def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]: +def linkcode_resolve(domain: str, info: dict[str, str]) -> t.Union[None, str]: """ Determine the URL corresponding to Python object. diff --git a/src/django_docutils/lib/directives/code.py b/src/django_docutils/lib/directives/code.py index 88145b94..e51cee96 100644 --- a/src/django_docutils/lib/directives/code.py +++ b/src/django_docutils/lib/directives/code.py @@ -71,11 +71,11 @@ def patch_bash_session_lexer() -> None: DEFAULT = HtmlFormatter(cssclass="highlight code-block", noclasses=INLINESTYLES) #: Add name -> formatter pairs for every variant you want to use -VARIANTS: t.Dict[str, "Formatter[str]"] = { +VARIANTS: dict[str, "Formatter[str]"] = { # 'linenos': HtmlFormatter(noclasses=INLINESTYLES, linenos=True), } -DEFAULT_OPTION_SPEC: t.Dict[str, t.Callable[[str], t.Any]] = dict.fromkeys( +DEFAULT_OPTION_SPEC: dict[str, t.Callable[[str], t.Any]] = dict.fromkeys( VARIANTS, directives.flag, ) @@ -90,7 +90,7 @@ class CodeBlock(Directive): option_spec = DEFAULT_OPTION_SPEC has_content = True - def run(self) -> t.List[nodes.Node]: + def run(self) -> list[nodes.Node]: """Directive run method for CodeBlock.""" self.assert_has_content() try: diff --git a/src/django_docutils/lib/metadata/extract.py b/src/django_docutils/lib/metadata/extract.py index 731e49d3..40dce804 100644 --- a/src/django_docutils/lib/metadata/extract.py +++ b/src/django_docutils/lib/metadata/extract.py @@ -26,7 +26,7 @@ def extract_title(document: nodes.document) -> t.Optional[str]: return None -def extract_metadata(document: nodes.document) -> t.Dict[str, str]: +def extract_metadata(document: nodes.document) -> dict[str, str]: """Return the dict containing document metadata. Parameters diff --git a/src/django_docutils/lib/metadata/process.py b/src/django_docutils/lib/metadata/process.py index cf61a081..f4d26b89 100644 --- a/src/django_docutils/lib/metadata/process.py +++ b/src/django_docutils/lib/metadata/process.py @@ -30,14 +30,12 @@ def process_datetime(metadata): See *processors.py* for more examples. """ -import typing as t - from django.utils.module_loading import import_string from django_docutils.lib.settings import DJANGO_DOCUTILS_LIB_RST -def process_metadata(metadata: t.Dict[str, str]) -> t.Dict[str, str]: +def process_metadata(metadata: dict[str, str]) -> dict[str, str]: """Return objects from RST metadata pulled from document source. This will turn things like string dates into time-zone'd dateutil objects. diff --git a/src/django_docutils/lib/metadata/processors.py b/src/django_docutils/lib/metadata/processors.py index eb99c512..000829a1 100644 --- a/src/django_docutils/lib/metadata/processors.py +++ b/src/django_docutils/lib/metadata/processors.py @@ -14,7 +14,7 @@ pass -def process_datetime(metadata: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]: +def process_datetime(metadata: dict[str, t.Any]) -> dict[str, t.Any]: """Optionally supports localizing times via pytz.""" timezone_formats = [ # timezone formats to try, most detailed to least "%Y-%m-%d %I:%M%p", @@ -41,7 +41,7 @@ def process_datetime(metadata: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]: return metadata -def process_anonymous_user(metadata: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]: +def process_anonymous_user(metadata: dict[str, t.Any]) -> dict[str, t.Any]: """Corrects name of author "anonymous" to django's anonymous username.""" if metadata.get("author") == "anonymous" and hasattr( settings, diff --git a/src/django_docutils/lib/publisher.py b/src/django_docutils/lib/publisher.py index 1c93b483..6ab89226 100644 --- a/src/django_docutils/lib/publisher.py +++ b/src/django_docutils/lib/publisher.py @@ -31,7 +31,7 @@ def publish_parts_from_doctree( settings_overrides: t.Optional[t.Any] = None, config_section: t.Optional[str] = None, enable_exit_status: bool = False, -) -> t.Dict[str, str]: +) -> dict[str, str]: """Render docutils doctree into docutils parts.""" reader = Reader(parser_name="null") pub = Publisher( diff --git a/src/django_docutils/lib/roles/common.py b/src/django_docutils/lib/roles/common.py index e48c9902..8822a7b8 100644 --- a/src/django_docutils/lib/roles/common.py +++ b/src/django_docutils/lib/roles/common.py @@ -14,7 +14,7 @@ def generic_url_role( name: str, text: str, url_handler_fn: "UrlHandlerFn", - innernodeclass: t.Type[t.Union[nodes.Text, nodes.TextElement]] = nodes.Text, + innernodeclass: type[t.Union[nodes.Text, nodes.TextElement]] = nodes.Text, ) -> "RoleFnReturnValue": """Docutils Role for Django Docutils. @@ -79,8 +79,8 @@ def generic_remote_url_role( name: str, text: str, url_handler_fn: "RemoteUrlHandlerFn", - innernodeclass: t.Type[t.Union[nodes.Text, nodes.TextElement]] = nodes.Text, -) -> t.Tuple[t.List[nodes.reference], t.List[t.Any]]: + innernodeclass: type[t.Union[nodes.Text, nodes.TextElement]] = nodes.Text, +) -> tuple[list[nodes.reference], list[t.Any]]: """Docutils Role that can call an external data source for title and URL. Same as generic_url_role, but can return url and title via external data source. diff --git a/src/django_docutils/lib/roles/email.py b/src/django_docutils/lib/roles/email.py index 02a554af..f34a5e59 100644 --- a/src/django_docutils/lib/roles/email.py +++ b/src/django_docutils/lib/roles/email.py @@ -14,7 +14,7 @@ def email_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, ) -> RoleFnReturnValue: """Role for linking to email articles. diff --git a/src/django_docutils/lib/roles/file.py b/src/django_docutils/lib/roles/file.py index b4554f68..0fc410c7 100644 --- a/src/django_docutils/lib/roles/file.py +++ b/src/django_docutils/lib/roles/file.py @@ -13,9 +13,9 @@ def file_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, -) -> t.Tuple[t.List[nodes.emphasis], t.List[t.Any]]: +) -> tuple[list[nodes.emphasis], list[t.Any]]: """Role for files. Examples @@ -66,9 +66,9 @@ def manifest_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, -) -> t.Tuple[t.List[nodes.emphasis], t.List[t.Any]]: +) -> tuple[list[nodes.emphasis], list[t.Any]]: """Role for manifests (package.json, file outputs). Examples @@ -103,9 +103,9 @@ def exe_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, -) -> t.Tuple[t.List[nodes.emphasis], t.List[t.Any]]: +) -> tuple[list[nodes.emphasis], list[t.Any]]: """Role for executables. Examples diff --git a/src/django_docutils/lib/roles/github.py b/src/django_docutils/lib/roles/github.py index c908f212..87ab3333 100644 --- a/src/django_docutils/lib/roles/github.py +++ b/src/django_docutils/lib/roles/github.py @@ -14,7 +14,7 @@ def github_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, ) -> RoleFnReturnValue: """Role for linking to GitHub repos and issues. diff --git a/src/django_docutils/lib/roles/hackernews.py b/src/django_docutils/lib/roles/hackernews.py index 4d8d267c..fe54bb47 100644 --- a/src/django_docutils/lib/roles/hackernews.py +++ b/src/django_docutils/lib/roles/hackernews.py @@ -15,7 +15,7 @@ def hackernews_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, ) -> RoleFnReturnValue: """Role for linking to hackernews articles. diff --git a/src/django_docutils/lib/roles/kbd.py b/src/django_docutils/lib/roles/kbd.py index d6fa17af..06fe1356 100644 --- a/src/django_docutils/lib/roles/kbd.py +++ b/src/django_docutils/lib/roles/kbd.py @@ -12,9 +12,9 @@ def kbd_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, -) -> t.Tuple[t.List[nodes.raw], t.List[t.Any]]: +) -> tuple[list[nodes.raw], list[t.Any]]: """Role for ````, the keyboard input element. Examples diff --git a/src/django_docutils/lib/roles/leanpub.py b/src/django_docutils/lib/roles/leanpub.py index 5a49b7c4..b1dc40de 100644 --- a/src/django_docutils/lib/roles/leanpub.py +++ b/src/django_docutils/lib/roles/leanpub.py @@ -14,7 +14,7 @@ def leanpub_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, ) -> RoleFnReturnValue: """Role for linking to leanpub page. diff --git a/src/django_docutils/lib/roles/pypi.py b/src/django_docutils/lib/roles/pypi.py index 63488269..4d46b810 100644 --- a/src/django_docutils/lib/roles/pypi.py +++ b/src/django_docutils/lib/roles/pypi.py @@ -14,7 +14,7 @@ def pypi_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, ) -> RoleFnReturnValue: """Role for linking to PyPI (Python Package Index) page. diff --git a/src/django_docutils/lib/roles/readthedocs.py b/src/django_docutils/lib/roles/readthedocs.py index 12fc2109..f65f13b9 100644 --- a/src/django_docutils/lib/roles/readthedocs.py +++ b/src/django_docutils/lib/roles/readthedocs.py @@ -14,7 +14,7 @@ def readthedocs_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, ) -> RoleFnReturnValue: """Role for linking to readthedocs.org page. diff --git a/src/django_docutils/lib/roles/registry.py b/src/django_docutils/lib/roles/registry.py index 0754e5d2..e22ea34e 100644 --- a/src/django_docutils/lib/roles/registry.py +++ b/src/django_docutils/lib/roles/registry.py @@ -77,7 +77,7 @@ def register_django_docutils_roles() -> None: return -def register_role_mapping(role_mapping: t.Dict[str, t.Any]) -> None: +def register_role_mapping(role_mapping: dict[str, t.Any]) -> None: """Register a dict mapping of roles. An item consists of a role name, import string to a callable, and an diff --git a/src/django_docutils/lib/roles/twitter.py b/src/django_docutils/lib/roles/twitter.py index 1320dfba..4134093d 100644 --- a/src/django_docutils/lib/roles/twitter.py +++ b/src/django_docutils/lib/roles/twitter.py @@ -14,7 +14,7 @@ def twitter_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, ) -> RoleFnReturnValue: """Role for linking to twitter articles. diff --git a/src/django_docutils/lib/roles/types.py b/src/django_docutils/lib/roles/types.py index 140f9256..8a7805ac 100644 --- a/src/django_docutils/lib/roles/types.py +++ b/src/django_docutils/lib/roles/types.py @@ -17,12 +17,12 @@ def __call__(self, target: str) -> str: class RemoteUrlHandlerFn(Protocol): """Protocol for role handler callback that retrieve from external data sources.""" - def __call__(self, target: str) -> t.Tuple[str, str]: + def __call__(self, target: str) -> tuple[str, str]: """Role function that can query an external source for its title.""" ... -RoleFnReturnValue = t.Tuple[t.List[nodes.reference], t.List[t.Any]] +RoleFnReturnValue = tuple[list[nodes.reference], list[t.Any]] """Role function return value. See also diff --git a/src/django_docutils/lib/roles/url.py b/src/django_docutils/lib/roles/url.py index 3f2d9410..d7f24a77 100644 --- a/src/django_docutils/lib/roles/url.py +++ b/src/django_docutils/lib/roles/url.py @@ -14,7 +14,7 @@ def url_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, ) -> RoleFnReturnValue: """Role for linking to url articles. diff --git a/src/django_docutils/lib/roles/wikipedia.py b/src/django_docutils/lib/roles/wikipedia.py index 5bfffe26..8ba570db 100644 --- a/src/django_docutils/lib/roles/wikipedia.py +++ b/src/django_docutils/lib/roles/wikipedia.py @@ -15,7 +15,7 @@ def wikipedia_role( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Optional[str] = None, ) -> RoleFnReturnValue: """Role for linking to Wikipedia articles. diff --git a/src/django_docutils/lib/transforms/code.py b/src/django_docutils/lib/transforms/code.py index 7b375ca2..47189f29 100644 --- a/src/django_docutils/lib/transforms/code.py +++ b/src/django_docutils/lib/transforms/code.py @@ -14,8 +14,8 @@ from pygments.token import _TokenType - TokenStream = Iterator[t.Tuple[_TokenType, str]] - TokenGenerator = Iterator[t.Tuple[t.Union[str, int], str]] + TokenStream = Iterator[tuple[_TokenType, str]] + TokenGenerator = Iterator[tuple[t.Union[str, int], str]] class InlineHtmlFormatter(HtmlFormatter): # type:ignore diff --git a/src/django_docutils/lib/transforms/toc.py b/src/django_docutils/lib/transforms/toc.py index 2e5a5c57..11843343 100644 --- a/src/django_docutils/lib/transforms/toc.py +++ b/src/django_docutils/lib/transforms/toc.py @@ -22,15 +22,15 @@ def build_contents( self, node: nodes.Node, level: int = 0, - ) -> t.Union[nodes.bullet_list, t.List[t.Any]]: + ) -> t.Union[nodes.bullet_list, list[t.Any]]: """Build nested bullet list from doctree content.""" assert isinstance(node, nodes.Element) level += 1 - sections: t.List[nodes.section] = [ + sections: list[nodes.section] = [ sect for sect in node.children if isinstance(sect, nodes.section) ] assert self.startnode is not None - entries: t.List[nodes.Node] = [] + entries: list[nodes.Node] = [] depth = ( self.startnode.details.get("depth", sys.maxsize) diff --git a/src/django_docutils/lib/types.py b/src/django_docutils/lib/types.py index c2127627..9fd8247f 100644 --- a/src/django_docutils/lib/types.py +++ b/src/django_docutils/lib/types.py @@ -1,14 +1,12 @@ """Typings for Django Docutils settings for django.""" -import typing as t - from typing_extensions import NotRequired, TypedDict class DjangoDocutilsLibRSTRolesSettings(TypedDict): """Docutils role mappings.""" - local: NotRequired[t.Dict[str, str]] + local: NotRequired[dict[str, str]] class DjangoDocutilsLibRSTDocutilsSettings(TypedDict): @@ -22,14 +20,14 @@ class DjangoDocutilsLibRSTDocutilsSettings(TypedDict): class DjangoDocutilsLibRSTSettings(TypedDict): """Core settings object for ``DJANGO_DOCUTILS_LIB_RST``.""" - metadata_processors: NotRequired[t.List[str]] - transforms: NotRequired[t.List[str]] + metadata_processors: NotRequired[list[str]] + transforms: NotRequired[list[str]] docutils: NotRequired[DjangoDocutilsLibRSTDocutilsSettings] - directives: NotRequired[t.Dict[str, str]] + directives: NotRequired[dict[str, str]] roles: NotRequired[DjangoDocutilsLibRSTRolesSettings] class DjangoDocutilsLibTextSettings(TypedDict): """Core settings object for ``DJANGO_DOCUTILS_TEXT_RST``.""" - uncapitalized_word_filters: t.List[str] + uncapitalized_word_filters: list[str] diff --git a/src/django_docutils/lib/utils.py b/src/django_docutils/lib/utils.py index ee90bba3..ec70a9b2 100644 --- a/src/django_docutils/lib/utils.py +++ b/src/django_docutils/lib/utils.py @@ -16,7 +16,7 @@ ws_re: "re.Pattern[str]" = re.compile(r"\s+") -def split_explicit_title(text: str) -> t.Tuple[bool, str, str]: +def split_explicit_title(text: str) -> tuple[bool, str, str]: """Split role content into title and target, if given (from sphinx).""" match = explicit_title_re.match(text) if match: diff --git a/src/django_docutils/lib/views.py b/src/django_docutils/lib/views.py index 8941e319..2603b4dc 100644 --- a/src/django_docutils/lib/views.py +++ b/src/django_docutils/lib/views.py @@ -24,7 +24,7 @@ class TitleMixin(ContextMixin): title = None subtitle = None - def get_context_data(self, **kwargs: object) -> t.Dict[str, t.Any]: + def get_context_data(self, **kwargs: object) -> dict[str, t.Any]: """:func:`django_docutils.lib.text.smart_title()` on title and subtitle.""" context = super().get_context_data(**kwargs) if self.title: @@ -40,7 +40,7 @@ class TemplateTitleView(TemplateView, TitleMixin): title = None subtitle = None - def get_context_data(self, **kwargs: object) -> t.Dict[str, t.Any]: + def get_context_data(self, **kwargs: object) -> dict[str, t.Any]: """Return context data.""" return super().get_context_data(**kwargs) @@ -113,7 +113,7 @@ class RSTRawView(TemplateTitleView): file_path: t.Optional[StrPath] = None title = None - def get_context_data(self, **kwargs: object) -> t.Dict[str, t.Any]: + def get_context_data(self, **kwargs: object) -> dict[str, t.Any]: """Merge content to context data.""" context = super().get_context_data(**kwargs) @@ -140,7 +140,7 @@ def raw_content(self) -> t.Optional[str]: with pathlib.Path(self.file_path).open(encoding="utf-8") as raw_content: return raw_content.read() - def get_context_data(self, **kwargs: object) -> t.Dict[str, t.Any]: + def get_context_data(self, **kwargs: object) -> dict[str, t.Any]: """Merge content and sidebar to context data.""" context = super().get_context_data(**kwargs) context["content"] = self.content diff --git a/src/django_docutils/lib/writers.py b/src/django_docutils/lib/writers.py index 066e4ef4..e79a12a9 100644 --- a/src/django_docutils/lib/writers.py +++ b/src/django_docutils/lib/writers.py @@ -14,9 +14,9 @@ class ParentNodeClassTuple(t.NamedTuple): """Typing for parent node accepting custom arguments.""" - parent_node_type: t.Type[t.Union[nodes.Node, nodes.Body]] - args: t.List[str] - kwargs: t.Dict[str, str] + parent_node_type: type[t.Union[nodes.Node, nodes.Body]] + args: list[str] + kwargs: dict[str, str] close_tag: t.Optional[str] @@ -104,7 +104,7 @@ def visit_title(self, node: nodes.Element) -> None: node["refid"] = node.parent["ids"][0] # specific cases we don't use h{1-6} tags for - parent_node_classes: t.List[ParentNodeClassTuple] = [ + parent_node_classes: list[ParentNodeClassTuple] = [ ParentNodeClassTuple( nodes.topic, ["p", ""], @@ -178,12 +178,12 @@ def _visit_section_title( Close tag for section title node. """ h_level = self.section_level + self.initial_header_level - 1 - atts: t.Dict[str, str] = {} + atts: dict[str, str] = {} if len(node.parent) >= 2 and isinstance(node.parent[1], nodes.subtitle): atts["CLASS"] = "subtitle" self.body.append(self.starttag(node, f"h{h_level}", "", **atts)) - attrs: t.Dict[str, str] = {} + attrs: dict[str, str] = {} if node.hasattr("refid"): attrs["class"] = "toc-backref" attrs["href"] = "#" + node["refid"] @@ -229,7 +229,7 @@ def __init__(self) -> None: # classes. (e.g. Python =< 2.1 classes) self.translator_class = DjangoDocutilsHTMLTranslator - def get_transforms(self) -> t.List[t.Type[Transform]]: + def get_transforms(self) -> list[type[Transform]]: """Return transformed required by DjangoDocutilsWriter. Adheres to DJANGO_DOCUTILS_LIB_RST settings. diff --git a/src/django_docutils/template.py b/src/django_docutils/template.py index 6ade8612..33cb7313 100644 --- a/src/django_docutils/template.py +++ b/src/django_docutils/template.py @@ -24,7 +24,7 @@ class DocutilsTemplates(BaseEngine): app_dirname: str = "templates" - def __init__(self, params: t.Dict[str, t.Any]) -> None: + def __init__(self, params: dict[str, t.Any]) -> None: params = params.copy() self.options = params.pop("OPTIONS").copy() self.options.setdefault("debug", settings.DEBUG) @@ -51,13 +51,13 @@ def get_template(self, template_name: str) -> "_EngineTemplate": class DocutilsTemplate: """Docutils template object for Django. Used by Docutils template engine.""" - def __init__(self, source: str, options: t.Dict[str, t.Any]) -> None: + def __init__(self, source: str, options: dict[str, t.Any]) -> None: self.source = source self.options = options def render( self, - context: t.Union["Context", t.Dict[str, t.Any], None] = None, + context: t.Union["Context", dict[str, t.Any], None] = None, request: t.Optional[HttpRequest] = None, ) -> "SafeString": """Render DocutilsTemplate to string.""" @@ -68,7 +68,7 @@ def render( context["csrf_token"] = csrf_token_lazy(request) context = {"source": self.source, "writer_name": "html"} - return mark_safe(t.cast(str, core.publish_parts(**context)["html_body"])) + return mark_safe(t.cast("str", core.publish_parts(**context)["html_body"])) register_pygments_directive() diff --git a/src/django_docutils/templatetags/django_docutils.py b/src/django_docutils/templatetags/django_docutils.py index 793e2350..54cf6702 100644 --- a/src/django_docutils/templatetags/django_docutils.py +++ b/src/django_docutils/templatetags/django_docutils.py @@ -20,8 +20,8 @@ class ReStructuredTextNode(Node): def __init__( self, content: t.Union[FilterExpression, str], - args: t.Optional[t.List[FilterExpression]] = None, - kwargs: t.Optional[t.Dict[str, FilterExpression]] = None, + args: t.Optional[list[FilterExpression]] = None, + kwargs: t.Optional[dict[str, FilterExpression]] = None, asvar: t.Optional[str] = None, ) -> None: self.content = content diff --git a/src/django_docutils/views.py b/src/django_docutils/views.py index d02cd8ee..f7cec8d2 100644 --- a/src/django_docutils/views.py +++ b/src/django_docutils/views.py @@ -18,9 +18,9 @@ class DocutilsResponse(TemplateResponse): def __init__( self, request: HttpRequest, - template: t.List[str], - rst: t.List[str], - context: t.Optional[t.Dict[str, t.Any]] = None, + template: list[str], + rst: list[str], + context: t.Optional[dict[str, t.Any]] = None, content_type: t.Optional[str] = None, status: t.Optional[int] = None, charset: t.Optional[str] = None, @@ -40,7 +40,7 @@ def __init__( @property def rendered_content(self) -> str: """Return freshly rendered content via docutils engine.""" - context: t.Dict[str, t.Any] = self.resolve_context(self.context_data) or {} + context: dict[str, t.Any] = self.resolve_context(self.context_data) or {} # we should be able to use the engine to .Render this from django.utils.safestring import mark_safe @@ -73,7 +73,7 @@ class DocutilsView(TemplateView): def render_to_response( self, - context: t.Optional[t.Dict[str, t.Any]] = None, + context: t.Optional[dict[str, t.Any]] = None, content_type: t.Optional[str] = None, status: t.Optional[int] = None, charset: t.Optional[str] = None, @@ -91,7 +91,7 @@ def render_to_response( using=using or self.template_engine, ) - def get_rst_names(self) -> t.List[str]: + def get_rst_names(self) -> list[str]: """Follows after get_template_names, but for scanning for rst content.""" if self.rst_name is None: raise DocutilsViewRstNameImproperlyConfigured diff --git a/tests/settings.py b/tests/settings.py index e8eba08f..2d1337e0 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -71,7 +71,7 @@ }, }, } -DJANGO_DOCUTILS_LIB_TEXT: t.Dict[str, t.List[str]] = { # Optional +DJANGO_DOCUTILS_LIB_TEXT: dict[str, list[str]] = { # Optional "uncapitalized_word_filters": ["project.my_module.my_capitalization_fn"], } INSTALLED_APPS = ("django_docutils",) diff --git a/tests/test_docutils_roles.py b/tests/test_docutils_roles.py index fc5205d2..da10ca35 100644 --- a/tests/test_docutils_roles.py +++ b/tests/test_docutils_roles.py @@ -82,7 +82,7 @@ class SphinxLikeRole: inliner: Inliner #: The ``docutils.parsers.rst.states.Inliner`` object. #: A dictionary of directive options for customisation #: (from the "role" directive). - options: t.Dict[str, t.Any] + options: dict[str, t.Any] #: A list of strings, the directive content for customisation #: (from the "role" directive). content: t.Sequence[str] @@ -94,9 +94,9 @@ def __call__( text: str, lineno: int, inliner: Inliner, - options: t.Optional[t.Dict[str, t.Any]] = None, + options: t.Optional[dict[str, t.Any]] = None, content: t.Sequence[str] = (), - ) -> t.Tuple[t.List[nodes.Node], t.List[t.Any]]: + ) -> tuple[list[nodes.Node], list[t.Any]]: """Return example class-based role.""" self.rawtext = rawtext self.text = text @@ -110,7 +110,7 @@ def __call__( self.name = name.lower() return self.run() - def run(self) -> t.Tuple[t.List[nodes.Node], t.List[t.Any]]: + def run(self) -> tuple[list[nodes.Node], list[t.Any]]: """Run docutils role.""" raise NotImplementedError @@ -157,7 +157,7 @@ def test_register_role_mapping() -> None: ) -GH_ROLE_TESTS: t.List[RoleContentFixture] = [ +GH_ROLE_TESTS: list[RoleContentFixture] = [ RoleContentFixture( test_id="gh-role-org", rst_content=":gh:`org`\n",