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

TYP,BUG: Reduce argument validation in C-based __class_getitem__ #22222

Merged
merged 1 commit into from Sep 7, 2022

Commits on Sep 7, 2022

  1. TYP,BUG: Reduce argument validation in C-based __class_getitem__ (n…

    …umpy#22212)
    
    Closes numpy#22185
    
    The __class_getitem__ implementations would previously perform basic validation of the passed value, i.e. it would check whether a tuple of the appropriate length was passed (e.g. np.dtype.__class_getitem__ would expect a single item or a length-1 tuple). As noted in aforementioned issue: this approach can cause issues when (a. 2 or more parameters are involved and (b. a subclasses is created one or more parameters are declared constant (e.g. a fixed dtype & variably shaped array).
    
    This PR fixes aforementioned issue by relaxing the runtime argument validation, thus mimicking the behavior of the standard library (more closely). While we could alternatively fix this by adding more special casing (e.g. only disable validation when cls is not np.ndarray), I'm not convinced this would be worth the additional complexity, especially since the standard library also has zero runtime validation for all of its Py_GenericAlias-based implementations of __class_getitem__.
    
    (Some edits by seberg to the commit message)
    BvB93 authored and charris committed Sep 7, 2022
    Copy the full SHA
    222cc37 View commit details
    Browse the repository at this point in the history