8000 BUG: Fixed an issue wherein `_GenericAlias.__getitem__` would raise for types with >1 parameters by BvB93 · Pull Request #19092 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fixed an issue wherein _GenericAlias.__getitem__ would raise for types with >1 parameters #19092

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

Merged
merged 2 commits into from
May 25, 2021

Conversation

BvB93
Copy link
Member
@BvB93 BvB93 commented May 25, 2021

Found and fixed a minor bug wherein _GenericAlias could raise under certain circumstances.

The issue was that only a single parameter was passed to underlying generic types,
even if aforementioned types would demand more than 1 parameter.

Examples

The behavior prior to this PR:

In [1]: from typing import TypeVar, Union
   ...: 
   ...: import numpy as np
   ...: import numpy.typing as npt
   ...: 
   ...: T1 = TypeVar("T1", bound=np.generic)
   ...: T2 = TypeVar("T2", bound=np.generic)
   ...: 
   ...: NDArray_A_or_B = npt.NDArray[Union[T1, T2]]

In [2]: NDArray_A_or_B[np.float32, np.float64]
  ...
TypeError: Too few parameters for typing.Union[~T1, ~T2]; actual 1, expected 2

@BvB93 BvB93 added this to the 1.21.0 release milestone May 25, 2021
@BvB93 BvB93 added the 09 - Backport-Candidate PRs tagged should be backported label May 25, 2021
@BvB93 BvB93 removed this from the 1.21.0 release milestone May 25, 2021
@BvB93 BvB93 removed the 09 - Backport-Candidate PRs tagged should be backported label May 25, 2021
@charris charris merged commit 5520a17 into numpy:main May 25, 2021
@charris
Copy link
Member
charris commented May 25, 2021

Thanks Bas.

@BvB93 BvB93 deleted the generic-alias-bug branch May 25, 2021 22:32
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
0