Skip to content

Commit

Permalink
Relax is_using_annotations() checks to work better with manually crea…
Browse files Browse the repository at this point in the history
…ted nodes
  • Loading branch information
tristanlatr committed Apr 1, 2024
1 parent 5302052 commit 7f9fb55
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pydoctor/astutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,20 @@ def is_using_typing_classvar(expr: Optional[ast.AST],
return is_using_annotations(expr, ('typing.ClassVar', "typing_extensions.ClassVar"), ctx)

def is_using_annotations(expr: Optional[ast.AST],
annotations:Sequence[str],
annotations: Collection[str],
ctx:'model.Documentable') -> bool:
"""
Detect if this expr is firstly composed by one of the specified annotation(s)' full name.
"""
full_name = node2fullname(expr, ctx)
if full_name in annotations:
full_name, dotted_name = node2fullname(expr, ctx), '.'.join(node2dottedname(expr))
if full_name in annotations or dotted_name in annotations:
return True
if isinstance(expr, ast.Subscript):
# Final[...] or typing.Final[...] expressions
if isinstance(expr.value, (ast.Name, ast.Attribute)):
value = expr.value
full_name = node2fullname(value, ctx)
if full_name in annotations:
full_name, dotted_name = node2fullname(value, ctx), '.'.join(node2dottedname(value))
if full_name in annotations or dotted_name in annotations:
return True
return False

Expand Down

0 comments on commit 7f9fb55

Please sign in to comment.