Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
This commit is contained in:
Takeshi KOMIYA 2024-10-06 03:10:07 +09:00 committed by GitHub
parent 09ab6edde5
commit 9323de2b3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 6 deletions

View File

@ -2507,7 +2507,7 @@ class UninitializedInstanceAttributeMixin(DataDocumenterMixinBase):
return self.objpath[-1] in annotations return self.objpath[-1] in annotations
def import_object(self, raiseerror: bool = False) -> bool: def import_object(self, raiseerror: bool = False) -> bool:
"""Check the exisitence of uninitialized instance attribute when failed to import """Check the existence of uninitialized instance attribute when failed to import
the attribute. the attribute.
""" """
try: try:
@ -2728,7 +2728,7 @@ class PropertyDocumenter(DocstringStripSignatureMixin, # type: ignore[misc]
return False return False
def import_object(self, raiseerror: bool = False) -> bool: def import_object(self, raiseerror: bool = False) -> bool:
"""Check the exisitence of uninitialized instance attribute when failed to import """Check the existence of uninitialized instance attribute when failed to import
the attribute. the attribute.
""" """
ret = super().import_object(raiseerror) ret = super().import_object(raiseerror)
@ -2801,7 +2801,7 @@ class PropertyDocumenter(DocstringStripSignatureMixin, # type: ignore[misc]
def autodoc_attrgetter(app: Sphinx, obj: Any, name: str, *defargs: Any) -> Any: def autodoc_attrgetter(app: Sphinx, obj: Any, name: str, *defargs: Any) -> Any:
"""Alternative getattr() for types""" """Alternative getattr() for types"""
for typ, func in app.registry.autodoc_attrgettrs.items(): for typ, func in app.registry.autodoc_attrgetters.items():
if isinstance(obj, typ): if isinstance(obj, typ):
return func(obj, name, *defargs) return func(obj, name, *defargs)

View File

@ -55,7 +55,7 @@ EXTENSION_BLACKLIST = {
class SphinxComponentRegistry: class SphinxComponentRegistry:
def __init__(self) -> None: def __init__(self) -> None:
#: special attrgetter for autodoc; class object -> attrgetter #: special attrgetter for autodoc; class object -> attrgetter
self.autodoc_attrgettrs: dict[type, Callable[[Any, str, Any], Any]] = {} self.autodoc_attrgetters: dict[type, Callable[[Any, str, Any], Any]] = {}
#: builders; a dict of builder name -> builder class #: builders; a dict of builder name -> builder class
self.builders: dict[str, type[Builder]] = {} self.builders: dict[str, type[Builder]] = {}
@ -113,7 +113,7 @@ class SphinxComponentRegistry:
#: post transforms; list of transforms #: post transforms; list of transforms
self.post_transforms: list[type[Transform]] = [] self.post_transforms: list[type[Transform]] = []
#: source paresrs; file type -> parser class #: source parsers; file type -> parser class
self.source_parsers: dict[str, type[Parser]] = {} self.source_parsers: dict[str, type[Parser]] = {}
#: source suffix: suffix -> file type #: source suffix: suffix -> file type
@ -132,6 +132,10 @@ class SphinxComponentRegistry:
# private cache of Docutils Publishers (file type -> publisher object) # private cache of Docutils Publishers (file type -> publisher object)
self.publishers: dict[str, Publisher] = {} self.publishers: dict[str, Publisher] = {}
@property
def autodoc_attrgettrs(self) -> dict[type, Callable[[Any, str, Any], Any]]:
return self.autodoc_attrgetters
def add_builder(self, builder: type[Builder], override: bool = False) -> None: def add_builder(self, builder: type[Builder], override: bool = False) -> None:
logger.debug('[app] adding builder: %r', builder) logger.debug('[app] adding builder: %r', builder)
if not hasattr(builder, 'name'): if not hasattr(builder, 'name'):
@ -377,7 +381,7 @@ class SphinxComponentRegistry:
def add_autodoc_attrgetter(self, typ: type, def add_autodoc_attrgetter(self, typ: type,
attrgetter: Callable[[Any, str, Any], Any]) -> None: attrgetter: Callable[[Any, str, Any], Any]) -> None:
self.autodoc_attrgettrs[typ] = attrgetter self.autodoc_attrgetters[typ] = attrgetter
def add_css_files(self, filename: str, **attributes: Any) -> None: def add_css_files(self, filename: str, **attributes: Any) -> None:
self.css_files.append((filename, attributes)) self.css_files.append((filename, attributes))