python / python/mypy

recognize staticmethod's __func__

Open
#11,211 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-descriptors topic-runtime-semantics
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the supplied staticmethod example with mypy and inspect how the type checker handles func access on the decorated methods. Trace the relevant staticmethod typing behavior and add or update a regression test for this snippet; done means the example passes mypy without the reported attribute errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.