python / python/mypy

No first-class bound method support

Open
#14,235 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

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


reveal_type(X().f)
reveal_type(X().f.__self__)

I'd expect X().f to be some Callable derived generic type for bound methods.
I'd expect X().f.__self__ to be typed X. Currently __self__ is defined in the typeshed for types.MethodType as returning object.

Playground: https://mypy-play.net/?mypy=latest&python=3.11&gist=0de8d7a90f1d3770b3b600052c1671b1

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 two reveal_type results in the linked mypy playground and compare them with the expected bound-method and self types. Done means bound methods have an appropriate generic Callable-derived type and self is inferred as X rather than object.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.