python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.22k stars 2.78k forks source link

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

Open davidhalter opened 4 years ago

davidhalter commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

JelleZijlstra commented 2 years ago

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:

AlexWaygood commented 2 years ago
  • 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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Fixing this issue will probably also fix