Skip to content

[mypyc] Allow abs() on native int types - #22367

Open
Pixeless001 wants to merge 1 commit into
python:masterfrom
Pixeless001:native-int-abs
Open

Pixeless001 wants to merge 1 commit into
python:masterfrom
Pixeless001:native-int-abs

Conversation

@Pixeless001

Copy link
Copy Markdown
Contributor

Follow-up to #22363.
abs() on an i64, i32, i16 or u8 failed to type check (Argument 1 to "abs" has incompatible type "i64"), because the native int classes in mypy's own mypy_extensions stubs define __neg__, __pos__ and __invert__ but not __abs__. This adds it to the bundled stubs and to the test stubs.

There's no specialized primitive for these types yet, so mypyc compiles the call through the generic PyNumber_Absolute path.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant