diff --git a/pytype/pyi/parser.py b/pytype/pyi/parser.py index e6bab8bc9..92d4a64b4 100644 --- a/pytype/pyi/parser.py +++ b/pytype/pyi/parser.py @@ -279,7 +279,11 @@ class _MetadataVisitor(visitor.BaseVisitor): def visit_Call(self, node): posargs = tuple(evaluator.literal_eval(x) for x in node.args) kwargs = {x.arg: evaluator.literal_eval(x.value) for x in node.keywords} - return (node.func.id, posargs, kwargs) + if isinstance(node.func, astlib.Attribute): + func_name = _attribute_to_name(node.func) + else: + func_name = node.func + return (func_name.id, posargs, kwargs) def visit_Dict(self, node): return evaluator.literal_eval(node) diff --git a/pytype/pyi/parser_test.py b/pytype/pyi/parser_test.py index 3404a1949..10bc90a4c 100644 --- a/pytype/pyi/parser_test.py +++ b/pytype/pyi/parser_test.py @@ -2885,6 +2885,19 @@ class Foo: x: Annotated[int, Signal] """) + def test_attribute_access_and_call(self): + self.check(""" + from typing import Annotated, Any + a: Any + def f() -> Annotated[list[int], a.b.C(3)]: ... + """, """ + from typing import Annotated, Any, List + + a: Any + + def f() -> Annotated[List[int], {'tag': 'call', 'fn': 'a.b.C', 'posargs': (3,), 'kwargs': {}}]: ... + """) + class ErrorTest(test_base.UnitTest): """Test parser errors."""