From 8e8a8f15970822a6242dc2ecba2ba4947204b4bb Mon Sep 17 00:00:00 2001 From: Josh Wilson Date: Tue, 9 Jun 2020 21:21:40 -0700 Subject: MAINT: make typing module available at runtime Closes https://github.com/numpy/numpy/issues/16550. This makes `np.typing.ArrayLike` and `np.typing.DtypeLike` available at runtime in addition to typing time. Some things to consider: - `ArrayLike` uses protocols, which are only in the standard library in 3.8+, but are backported in `typing_extensions`. This conditionally imports `Protocol` and sets `_SupportsArray` to `Any` at runtime if the module is not available to prevent NumPy from having a hard dependency on `typing_extensions`. Since e.g. mypy already includes `typing_extensions` as a dependency, anybody actually doing type checking will have it set correctly. - We are starting to hit the edges of "the fiction of the stubs". In particular, they could just cram everything into `__init__.pyi` and ignore the real structure of NumPy. But now that typing is available a runtime, we have to e.g. carefully import `ndarray` from `numpy` in the typing module and not from `..core.multiarray`, because otherwise mypy will think you are talking about a different ndarray. We will probably need to do some shuffling the stubs into more fitting locations to mitigate weirdness like this. --- numpy/setup.py | 1 + 1 file changed, 1 insertion(+) (limited to 'numpy/setup.py') diff --git a/numpy/setup.py b/numpy/setup.py index c6498d101..cbf633504 100644 --- a/numpy/setup.py +++ b/numpy/setup.py @@ -17,6 +17,7 @@ def configuration(parent_package='',top_path=None): config.add_subpackage('polynomial') config.add_subpackage('random') config.add_subpackage('testing') + config.add_subpackage('typing') config.add_data_dir('doc') config.add_data_files('py.typed') config.add_data_files('*.pyi') -- cgit v1.2.1