33import importlib
44import inspect
55import re
6- from typing import TYPE_CHECKING , Dict , List , NamedTuple , Optional , Sequence , Tuple
6+ from collections .abc import Sequence
7+ from typing import TYPE_CHECKING , NamedTuple
78
89from docutils import nodes
910from sphinx import addnodes
1314from sphinx .util .docutils import SphinxDirective
1415from sphinx .util .typing import OptionSpec
1516
17+
1618if TYPE_CHECKING :
1719 from .builder import DPYHTML5Translator
1820
@@ -96,7 +98,7 @@ class PyAttributeTable(SphinxDirective):
9698 final_argument_whitespace = False
9799 option_spec : OptionSpec = {}
98100
99- def parse_name (self , content : str ) -> Tuple [str , str ]:
101+ def parse_name (self , content : str ) -> tuple [str , str ]:
100102 match = _name_parser_regex .match (content )
101103 if match is None :
102104 raise RuntimeError (f"content { content } somehow doesn't match regex in { self .env .docname } ." )
@@ -112,7 +114,7 @@ def parse_name(self, content: str) -> Tuple[str, str]:
112114
113115 return modulename , name
114116
115- def run (self ) -> List [attributetableplaceholder ]:
117+ def run (self ) -> list [attributetableplaceholder ]:
116118 """If you're curious on the HTML this is meant to generate:
117119
118120 <div class="py-attribute-table">
@@ -149,7 +151,7 @@ def run(self) -> List[attributetableplaceholder]:
149151 return [node ]
150152
151153
152- def build_lookup_table (env : BuildEnvironment ) -> Dict [str , List [str ]]:
154+ def build_lookup_table (env : BuildEnvironment ) -> dict [str , list [str ]]:
153155 # Given an environment, load up a lookup table of
154156 # full-class-name: objects
155157 result = {}
@@ -178,7 +180,7 @@ def build_lookup_table(env: BuildEnvironment) -> Dict[str, List[str]]:
178180class TableElement (NamedTuple ):
179181 fullname : str
180182 label : str
181- badge : Optional [ attributetablebadge ]
183+ badge : attributetablebadge | None
182184
183185
184186def process_attributetable (app : Sphinx , doctree : nodes .Node , fromdocname : str ) -> None :
@@ -203,12 +205,12 @@ def process_attributetable(app: Sphinx, doctree: nodes.Node, fromdocname: str) -
203205
204206
205207def get_class_results (
206- lookup : Dict [str , List [str ]], modulename : str , name : str , fullname : str
207- ) -> Dict [str , List [TableElement ]]:
208+ lookup : dict [str , list [str ]], modulename : str , name : str , fullname : str
209+ ) -> dict [str , list [TableElement ]]:
208210 module = importlib .import_module (modulename )
209211 cls = getattr (module , name )
210212
211- groups : Dict [str , List [TableElement ]] = {
213+ groups : dict [str , list [TableElement ]] = {
212214 _ ("Attributes" ): [],
213215 _ ("Methods" ): [],
214216 }
0 commit comments