mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
shrink whitelist for `sphinx.ext.autodoc.type_comment
` (#11400)
Co-authored-by: daniel.eades <daniel.eades@hotmail.com>
This commit is contained in:
parent
f06ef37017
commit
edd9ea0a39
@ -324,7 +324,6 @@ module = [
|
||||
"sphinx.ext.autodoc.mock",
|
||||
"sphinx.ext.autodoc.importer",
|
||||
"sphinx.ext.autodoc.preserve_defaults",
|
||||
"sphinx.ext.autodoc.type_comment",
|
||||
"sphinx.ext.autosummary",
|
||||
"sphinx.ext.autosummary.generate",
|
||||
"sphinx.ext.doctest",
|
||||
|
@ -88,14 +88,19 @@ def get_type_comment(obj: Any, bound_method: bool = False) -> Signature | None:
|
||||
# subject is placed inside class or block. To read its docstring,
|
||||
# this adds if-block before the declaration.
|
||||
module = ast.parse('if True:\n' + source, type_comments=True)
|
||||
subject = cast(ast.FunctionDef, module.body[0].body[0]) # type: ignore
|
||||
subject = cast(
|
||||
ast.FunctionDef, module.body[0].body[0], # type: ignore[attr-defined]
|
||||
)
|
||||
else:
|
||||
module = ast.parse(source, type_comments=True)
|
||||
subject = cast(ast.FunctionDef, module.body[0])
|
||||
|
||||
if getattr(subject, "type_comment", None):
|
||||
function = ast.parse(subject.type_comment, mode='func_type', type_comments=True)
|
||||
return signature_from_ast(subject, bound_method, function) # type: ignore
|
||||
type_comment = getattr(subject, "type_comment", None)
|
||||
if type_comment:
|
||||
function = ast.parse(type_comment, mode='func_type', type_comments=True)
|
||||
return signature_from_ast(
|
||||
subject, bound_method, function, # type: ignore[arg-type]
|
||||
)
|
||||
else:
|
||||
return None
|
||||
except (OSError, TypeError): # failed to load source code
|
||||
|
Loading…
Reference in New Issue
Block a user