Skip to content

Forward reference to decorated class method has type Any #4485

Closed

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):

from typing import TypeVar, Callable

T = TypeVar('T')
def dec() -> Callable[[T], T]: pass

class A:
    @classmethod
    def f(cls) -> None:
        reveal_type(cls.g)  # Any  <-- unexpected

    @classmethod
    @dec()
    def g(cls, x: str) -> None:
        pass

    @classmethod
    def h(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.

Activity

  1. self-assigned this
    on Jan 18, 2018
  2. added a commit that references this issue on Jan 18, 2018
    5a3109c
  3. added a commit that references this issue on Feb 19, 2018
    3545a71
  4. added a commit that references this issue on Mar 15, 2018
    7f3cbf3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions