numpy/numpy-stubs

Add typing_extensions as a dependency

person142 opened this issue · 4 comments

The typing_extensions module contains backports of new typing features for earlier versions of Python. It is understood by type checkers like Mypy and Pyre. In #59 it is proposed that we add it as a dependency, which I think is a good idea. Beyond just that PR, some potential benefits are:

  • Using Literal to better type specific (but fairly common) overloads, e.g.
    np.array(..., dtype="float")
  • Protocol might be a good way to approach typing ArrayLike
  • Using TypedDict to better describe complex dtypes.

I imagine that the biggest concern would be forcing it to be a hard dependency of NumPy should the stubs be moved there, but I believe we can avoid that.

  • If everything stays stubs only, then it's not a problem

  • If we do add annotations to source files, we can still work around it with constructs like

    from typing import TYPE_CHECKING
    
    if TYPE_CHECKING:
        from typing_extensions import Literal
    
    x: 'Literal[1]' = 1  # Or use `from __future__ import annotations` post 3.8
    ...

Objections? In the absence of them we'll move forward with including it.

Sounds like a good idea to me

BvB93 commented

A separate pull request has just been created for the addition of typing_extensions (#63).

Thanks. I’ll give people a little bit longer to raise any objections here, and then we’ll move forward.

Closed by #63.