Skip to content

Overriding of methods with self types #2353

Open

Description

@JukkaL

It's unclear how we should check overrides of methods that use self types (e.g. self: T). There is some discussion in #2193.

A relevant comment (but there are others): #2193 (comment)

Activity

  1. added this to the milestone on Oct 27, 2016
  2. ilevkivskyi commented on Nov 8, 2016

    @ilevkivskyi
    Member

    @JukkaL

    I tried to left a (really long) comment here a week ago. But it looks like something went wrong. I suppose I just forgot to press "Comment" :-(

    It is difficult to reproduce it again now, but very short summary is: Now I am in favour of option (4) you proposed in #2193 (comment)

  3. gvanrossum commented on Nov 8, 2016

    @gvanrossum
    Member

    Now I am in favour of option (4) you proposed in #2193 (comment)
    #2193 (comment)

    Agreed.

  4. JukkaL commented on Nov 30, 2016

    @JukkaL
    CollaboratorAuthor

    The duplicate issue #2511 has a relevant example that has a class method.

  5. removed this from the milestone on Mar 29, 2017
  6. tyrion commented on Aug 22, 2019

    @tyrion
    Contributor

    The following example seems related to this issue:

    S = TypeVar("S")
    T = TypeVar("T")
    
    F = TypeVar("F", bound="Foo[Any, Any]")
    class Foo(Generic[S, T]):
        def test(self: F) -> F:
            raise NotImplementedError
    
    B = TypeVar("B", bound="Bar[Any]")
    class Bar(Foo[int, T], Generic[T]):
        def test(self: B) -> B:
            return self

    mypy tells me Return type "Bar[T]" of "test" incompatible with return type "Bar[int]" in supertype "Foo" But I cannot understand what it means with Bar[int].

    As requested by @ilevkivskyi on gitter, I am adding a comment here.

  7. slessans commented on Jan 5, 2021

    @slessans

    The following example seems related to this issue:

    S = TypeVar("S")
    T = TypeVar("T")
    
    F = TypeVar("F", bound="Foo[Any, Any]")
    class Foo(Generic[S, T]):
        def test(self: F) -> F:
            raise NotImplementedError
    
    B = TypeVar("B", bound="Bar[Any]")
    class Bar(Foo[int, T], Generic[T]):
        def test(self: B) -> B:
            return self

    mypy tells me Return type "Bar[T]" of "test" incompatible with return type "Bar[int]" in supertype "Foo" But I cannot understand what it means with Bar[int].

    As requested by @ilevkivskyi on gitter, I am adding a comment here.

    @tyrion wondering if there was any progress made on this or if there is a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions