data-apis / array-api

RFC document, tooling and other content related to the array API standard
https://data-apis.github.io/array-api/latest/
MIT License
205 stars 42 forks source link

Disallowed typing in `linalg.vector_norm` #817

Open lucascolley opened 4 days ago

lucascolley commented 4 days ago

Spec:

ord: int | float | ~typing.Literal[inf, -inf] = 2

Stubs:

ord: Union[int, float, Literal[inf, -inf]] = 2

Literals docs

The following are provisionally disallowed for simplicity. We can consider allowing them in the future.

  • Floats: e.g. Literal[3.14]. Representing Literals of infinity or NaN in a clean way is tricky; real-world APIs are unlikely to vary their behavior based on a float parameter.

A relevant issue: https://github.com/python/typing/issues/1160


I don't know if anything can be done, and this was probably done deliberately, but useful to have an issue nonetheless.

asmeurer commented 4 days ago

Yes, this is a known issue. There are some instances where the Python typing rules disallow certain things and we've opted to keep the annotations accurate in those cases. Implementations may need to adjust them until the upstream typing rules can be fixed.