typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Remove type checker-specific symbols from builtins.pyi and typing.pyi

Open JelleZijlstra opened this issue 2 years ago • 1 comments

I'm working to get rid of the type checker-specific symbols that currently are in our core stubs but don't exist at runtime. I'll use this issue to track the work needed. This involves changes both to typeshed and to type checkers.

Affected names:

  • typing._TypedDict. Suggesting to rename to _typeshed.TypedDictFallback. (mypy and pyright)
  • typing._promote -> _typeshed._promote (mypy only)
  • typing.AwaitableGenerator -> _typeshed.AwaitableGenerator (mypy and pyright)
  • builtins.function (mypy and pyright). Need to look more into why we can't just use types.FunctionType.
    • Working on this in mypy but it requires updating a ton of test cases
  • builtins.ellipsis (mypy and pyright). Should add a new name to _typeshed, similar to NoneType.

builtins.module was also mentioned in the past but it's been fixed already (mypy PR: https://github.com/python/mypy/pull/3107).

Linked issues and PRs:

  • #2999
  • #3556
  • #3932
  • python/mypy#11564
  • python/mypy#8240
  • https://github.com/python/mypy/issues/2765
  • https://github.com/python/mypy/issues/8699

JelleZijlstra avatar Apr 03 '22 00:04 JelleZijlstra

  • https://github.com/python/mypy/issues/5958

contains some insight into why builtins.function and types.FunctionType used to be different.

But changes that we made to builtins.function in typeshed (to reduce false-positives) mean that they're not so different anymore, e.g.:

  • #6804

AlexWaygood avatar Apr 03 '22 00:04 AlexWaygood