Content-Length: 228533 | pFad | https://github.com/python/mypy/issues/14235

3E No first-class bound method support · Issue #14235 · python/mypy · GitHub
Skip to content

No first-class bound method support #14235

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

Open
ikonst opened this issue Dec 2, 2022 · 1 comment
Open

No first-class bound method support #14235

ikonst opened this issue Dec 2, 2022 · 1 comment
Labels
bug mypy got something wrong

Comments

@ikonst
Copy link
Contributor

ikonst commented Dec 2, 2022

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

@ikonst ikonst added the bug mypy got something wrong label Dec 2, 2022
@jorenham
Copy link
Contributor

jorenham commented May 29, 2025

For what it's worth: With mypy 1.15 this is still an issue, and Pyright behaves correctly. This is also an issue for unbound methods.

class A:
    def f(self) -> None: ...

reveal_type(A.f.__self__)   # mypy ❌ [attr-defined], pyright ✅ type[A]
reveal_type(A().f.__self__) # mypy ❌ [attr-defined], pyright ✅ A
main.py:4: error: "Callable[[A], None]" has no attribute "__self__"  [attr-defined]
main.py:5: error: "Callable[[], None]" has no attribute "__self__"  [attr-defined]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/python/mypy/issues/14235

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy