Skip to content
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

Don't use builtins.function and others anymore #8240

Open
davidhalter opened this issue Jan 5, 2020 · 7 comments
Open

Don't use builtins.function and others anymore #8240

davidhalter opened this issue Jan 5, 2020 · 7 comments
Assignees
Labels

Comments

@davidhalter
Copy link

There are at least two classes in typeshed's builtins.pyi (
class function and class ellipsis, that should not belong there.

The issues in typeshed are:

However, typeshed's CI will break if you still use these classes. Please find another way to implement this and let typeshed remove those classes (respectively rename ellipsis to _ellipsis).

The problem is that other software does depend on typeshed as well and for example Jedi this leads to bugs.

@JukkaL
Copy link
Collaborator

JukkaL commented Jan 6, 2020

Fair enough, these don't really belong to typeshed. Renaming ellipsis to _ellipsis should be pretty straightforward. It's somewhat non-trivial to modify mypy to not depend on the function type, however. One idea would be to introduce a mypy-specific stub file that defines function (such as _mypy_builtins) and implicitly import that module within mypy.

@msullivan
Copy link
Collaborator

We could do the underscore thing for _function also, right?

@JelleZijlstra
Copy link
Member

I'm interested in pushing this through in order to help clean up typeshed. I need to think more about the exact approach, but some thoughts:

  • We should either put these "fake" types in _typeshed or use the existing public names (e.g. types.FunctionType)
  • Before doing this, should make sure typeshed is safely synced to mypy so that further changes are easy
  • Affected names include builtins.function, builtins.ellipsis, typing.AwaitableGenerator
  • Should also check on what other type checkers need. pytype uses its own builtins.pyi so shouldn't care; pyright already uses _typeshed.NoneType for similar purposes.

@AlexWaygood
Copy link
Member

  • Affected names include builtins.function, builtins.ellipsis, typing.AwaitableGenerator

There's also typing._TypedDict — the comment in the typeshed stub implies that this is only used by mypy.

@erictraut
Copy link

Pyright uses all four of these symbols too: builtins.function, builtins.ellipsis, typing.AwaitableGenerator and typing._TypedDict. If you're going to remove, move or rename these in typeshed, please let me know so I can update pyright's logic accordingly. Thanks!

@JelleZijlstra
Copy link
Member

There is also typing._promote, which sets up a fake subclass relationship for mypy: https://mypy-play.net/?mypy=latest&python=3.10&gist=74f80ff35ef1f4edc66302c70a225b50

@AlexWaygood

This comment was marked as resolved.

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

No branches or pull requests

7 participants