Skip to content

Forward reference to decorated class method has type Any #4485

Description

@JukkaL

In the program below, the type inferred for cls.g in A.f is Any, even though it should be def (x: builtins.str):

fromtypingimportTypeVar, CallableT=TypeVar('T')
defdec() ->Callable[[T], T]: passclassA:
@classmethoddeff(cls) ->None:
reveal_type(cls.g) # Any <-- unexpected@classmethod@dec()defg(cls, x: str) ->None:
pass@classmethoddefh(cls) ->None:
reveal_type(cls.g) # def (x: builtins.str) <-- ok

This works correctly when the decorated method is accessed using an instance type (such as self).

In fine-grained incremental mode the types can be more precise, which can result in additional errors in fine-grained incremental mode.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions