python / python/mypy

Does not recognize __func__ of methods

Open
#14,123 0 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

seems similar to #2563, #3482, #8869, #11211, #12673 -- though those are mostly about decorated descriptors

Bug Report

simple, silly example:

class C:
    def f(self) -> None: pass

    def g(self) -> None:
        print(self.f.__func__)

C().g()

Expected Behavior

no error

Actual Behavior

$ ./.venv/bin/mypy t.py
t.py:5: error: "Callable[[], None]" has no attribute "__func__"  [attr-defined]
Found 1 error in 1 file (checked 1 source file)
$ ./.venv/bin/mypy --version
mypy 0.991 (compiled: yes)

Your Environment

  • Mypy version used: 0.991
  • Mypy command-line flags: N/A
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: 3.8.10

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 reproducing the report with the Python snippet in t.py and the documented mypy 0.991 command. Trace how mypy infers the type of self.f and handles access to func. Done means the example type-checks without the attr-defined error while existing method and descriptor checks remain passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
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.