Skip to content

Fix class method and static method calls with --export-ref-info #15282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions mypy/refinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

from __future__ import annotations

from mypy.nodes import LDEF, Expression, MemberExpr, MypyFile, NameExpr, RefExpr
from mypy.nodes import (
LDEF,
Expression,
MemberExpr,
MypyFile,
NameExpr,
RefExpr,
SymbolNode,
TypeInfo,
)
from mypy.traverser import TraverserVisitor
from mypy.typeops import tuple_fallback
from mypy.types import (
Expand Down Expand Up @@ -36,8 +45,11 @@ def record_ref_expr(self, expr: RefExpr) -> None:
fullname = expr.fullname
elif isinstance(expr, MemberExpr):
typ = self.type_map.get(expr.expr)
sym = None
if isinstance(expr.expr, RefExpr):
sym = expr.expr.node
if typ:
tfn = type_fullname(typ)
tfn = type_fullname(typ, sym)
if tfn:
fullname = f"{tfn}.{expr.name}"
if not fullname:
Expand All @@ -46,13 +58,15 @@ def record_ref_expr(self, expr: RefExpr) -> None:
self.data.append({"line": expr.line, "column": expr.column, "target": fullname})


def type_fullname(typ: Type) -> str | None:
def type_fullname(typ: Type, node: SymbolNode | None = None) -> str | None:
typ = get_proper_type(typ)
if isinstance(typ, Instance):
return typ.type.fullname
elif isinstance(typ, TypeType):
return type_fullname(typ.item)
elif isinstance(typ, FunctionLike) and typ.is_type_obj():
if isinstance(node, TypeInfo):
return node.fullname
return type_fullname(typ.fallback)
elif isinstance(typ, TupleType):
return type_fullname(tuple_fallback(typ))
Expand Down