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

MAINT: Ensure that re-exported sub-modules are properly annotated #18636

Merged
merged 3 commits into from Mar 17, 2021

Conversation

BvB93
Copy link
Member

@BvB93 BvB93 commented Mar 17, 2021

Backport of #18618.

xref #18601.

Sub-modules, such as np.linalg, must be explicitly imported in the main namespaces' stub file if one wants
to access the sub-module via a getattr operation, i.e. so that one can directly use np.linalg.norm rather
than import numpy.linalg; np.linalg.norm.

While this was taken care of in the main numpy namespace, the relevant annotations were missing for others
such as np.lib.*. This PR fixes aforementioned issue.

Examples

The behavior prior to this PR:

>>> import numpy as np

>>> x = np.arange(6)
>>> out = np.lib.stride_tricks.sliding_window_view(x, 3)

Mypy output:

test.pyi:4:7: error: Module has no attribute "stride_tricks"  [attr-defined]

Bas van Beek added 3 commits March 17, 2021 14:36
With `as_strided`, and the newly introduced `sliding_window_view` function, there are currently 2 public objects that can:
a. Only be imported from a private module
b. Are publicly documented to-be imported from aforementioned module

Both observations are problematic and in need of rectification.
This commit therefore moves `np.lib.stride_tricks` to the `PUBLIC_MODULES` list.
Ensures that type checkers will allow the likes of:

>>> import numpy as np
>>> out = np.lib.stride_tricks.sliding_window_view(...)
… list

Aforementioned module was accidently marked as public
@BvB93 BvB93 added this to the 1.20.2 release milestone Mar 17, 2021
@charris charris merged commit 031e411 into numpy:maintenance/1.20.x Mar 17, 2021
@charris
Copy link
Member

charris commented Mar 17, 2021

Thanks Bas.

@BvB93 BvB93 deleted the modules2 branch March 19, 2021 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants