Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TYP: Optionalnumpy.number type parameters#27736

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

jorenham
Copy link
Member

The type parameters ofnp.number and its abstract subtypes now default toAny.
This means that typecheckers will now infernp.floating asnp.floating[Any], instead of rejecting it (when configured in strict mode).

This affects


The reason for choosingAny as the default, instead of setting it to the upper bound (numpy.typing.NBitBase), is because these type parameters (TypeVars) are invariant.
If they weren't invariant, thenx: int16 = int8(3) would be a valid statement, which we probably don't want. So the invariance means thatx: number[NBitBase] = int8(3) is rejected, butx: number[Any] = int8(3) is accepted.

I usually tend to avoid usingAny, but because those_NBit type-parameters aren't actually annotating anything, theAny won't affect anything "outside" of thenumber types, so it's no problem to use it here.

@jorenhamjorenham added the 56 - Needs Release Note.Needs an entry in doc/release/upcoming_changes labelNov 11, 2024
@jorenhamjorenham removed the 56 - Needs Release Note.Needs an entry in doc/release/upcoming_changes labelNov 12, 2024
@charrischarris merged commit8c46459 intonumpy:mainNov 14, 2024
69 checks passed
@charris
Copy link
Member

Thanks Joren.

jorenham reacted with laugh emoji

@jorenhamjorenham deleted the typing/scalar-type-parameter-defaults branchNovember 14, 2024 17:59
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@jorenham@charris

[8]ページ先頭

©2009-2025 Movatter.jp