Skip to content
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

recognize staticmethod's __func__ #11211

Open
kcwu opened this issue Sep 28, 2021 · 1 comment
Open

recognize staticmethod's __func__ #11211

kcwu opened this issue Sep 28, 2021 · 1 comment
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes topic-runtime-semantics mypy doesn't model runtime semantics correctly

Comments

@kcwu
Copy link

kcwu commented Sep 28, 2021

To Reproduce

Run mypy against this code

class A(object):
    @staticmethod
    def open():
        return 123
    @staticmethod
    def proccess():
        return 456

    switch = {
        1: open.__func__,
        2: proccess.__func__,   
    }

p.s. this code snippet is copied from the first solution of https://stackoverflow.com/questions/41921255/staticmethod-object-is-not-callable

Expected Behavior

This code snippet should pass mypy's check.

Actual Behavior

s.py:10: error: "Callable[[], Any]" has no attribute "__func__"
s.py:11: error: "Callable[[], Any]" has no attribute "__func__"
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: just file name
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.9.7
  • Operating system and version: Debian rodete
@kcwu kcwu added the bug mypy got something wrong label Sep 28, 2021
@sobolevn
Copy link
Member

sobolevn commented Sep 29, 2021

The problem here is that we infer proccess to be just Callable with no extra metadata. Probably, we can change @staticmethod and @classmethod to be a protocol with __call__ and __func__ (and any other props).

@JelleZijlstra @hauntsaninja what do you think? 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-descriptors Properties, class vs. instance attributes topic-runtime-semantics mypy doesn't model runtime semantics correctly
Projects
None yet
Development

No branches or pull requests

3 participants