Skip to content

ENH: Improve the placeholder annotations for the main numpy namespace (part 2)#18780

Merged
charris merged 2 commits intonumpy:mainfrom
BvB93:placeholder3
Apr 16, 2021
Merged

ENH: Improve the placeholder annotations for the main numpy namespace (part 2)#18780
charris merged 2 commits intonumpy:mainfrom
BvB93:placeholder3

Conversation

@BvB93
Copy link
Copy Markdown
Member

@BvB93 BvB93 commented Apr 15, 2021

Follow up on #18765.

This PR makes two new sets of improvements to the placeholder annotations:

  • Replaces the Type[Any] annotations of the classes with explicit class definitions. The former can cause issues as mypy does not allow one to inherit from such objects (e.g. MAINT: Add inline type hintings for stats.qmc scipy/scipy#13833 (comment)).
  • Replaces the Callable[..., Any] annotation of the C-based functions with explicit function definitions. The relevant signatures were herein adapted from the functions' docstring.

Bas van Beek added 2 commits April 15, 2021 13:44
Use explicitly defined classes rather than annotating them as `Type[Any]`.
The latter currently causes issues with mypy, which does not allow it to be used as a baseclass (because reasons?)
All new function definitions based on the respective functions' docstring
def concatenate(__a, axis=..., out=..., dtype=..., casting=...): ...
def copyto(dst, src, casting=..., where=...): ...
def datetime_as_string(arr, unit=..., timezone=..., casting=...): ...
def datetime_data(__dtype): ...
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double leading underscore is used for denoting position-only arguments per PEP 484. The newer /-based syntax introduced in PEP 570 is, unfortunatelly, not yet supported by mypy for python versions prior to python 3.8.

@charris charris merged commit ea0bf54 into numpy:main Apr 16, 2021
@charris
Copy link
Copy Markdown
Member

charris commented Apr 16, 2021

Thanks Bas.

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.

2 participants