Skip to content

Improve the self types situation #5676

Closed

Description

@JelleZijlstra

From micro codery on typing-sig:

It was only after seeing the solution that I could find docs describing it on mypy.readthedocs. There is a note claiming that a generic self is still experimental but maybe a convention should be added to the typeshed contributing guide about using it, just like Sequence is recommended over list.

From @srittau on #5675:

I suggest that in the future we shouldn't accept __enter__() methods returning self anymore that don't use a type var.

I think we should do both of these things. We can find some existing offenders with git grep 'def __enter__(self) -> [A-Z]'.

Activity

  1. srittau commented on Jun 22, 2021

    @srittau
    Collaborator

    We can also add a Self type var to _typeshed:

    Self = TypeVar("Self")

    This can help us finding places where we should use typing.Self if this proposal is accepted.

  2. added a commit that references this issue on Jun 27, 2021
  3. gruebel commented on Jul 6, 2021

    @gruebel
    Contributor

    I think all of the work is done in the stdlib, except for Python 2 types. Do you also want to tackle it or just leave it as it is?

  4. srittau commented on Jul 6, 2021

    @srittau
    Collaborator

    Personally, I would not put the work into Python 2 stubs, but I would accept PRs improving them.

  5. gruebel commented on Jul 6, 2021

    @gruebel
    Contributor

    I'm also not up to put some work into Python 2 stubs 😄 so next would be the stubs under the stubs folder, right?

  6. JelleZijlstra commented on Dec 14, 2021

    @JelleZijlstra
    MemberAuthor

    Looks like there's no work left. (I forgot what Python 2 is.)

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions