Skip to content

No first-class bound method support #14235

Open
@ikonst

Description

@ikonst
Contributor
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

Activity

jorenham

jorenham commented on May 29, 2025

@jorenham
Contributor

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ikonst@jorenham

        Issue actions

          No first-class bound method support · Issue #14235 · python/mypy