Skip to content

recognize staticmethod's __func__ #11211

Open

Description

@kcwu

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

Activity

  1. added
    bugmypy got something wrong
    on Sep 28, 2021
  2. sobolevn commented on Sep 29, 2021

    @sobolevn
    Member

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-descriptorsProperties, class vs. instance attributestopic-runtime-semanticsmypy doesn't model runtime semantics correctly

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions