Skip to content

Preserve exact integer conversion for subclasses - #405

Merged
dgilland merged 1 commit into
dgilland:developfrom
boogu2005:codex/to-integer-subclass-precision
Nov 1, 2026
Merged

dgilland merged 1 commit into
dgilland:developfrom
boogu2005:codex/to-integer-subclass-precision

Conversation

@boogu2005

Copy link
Copy Markdown
Contributor

Integer subclasses such as IntEnum, and str subclasses containing integer text, currently fall through to float conversion in to_integer(). For example, 9007199254740993 becomes 9007199254740992, and sufficiently large values become 0 after float overflow.

Use exact built-in integer conversion for subclasses that retain the default conversion protocol. Explicitly overridden float methods keep their existing behavior. The returned value remains a built-in int, including for bool inputs.

Regression tests cover positive and negative large integers, IntEnum, int/str subclasses, and floating-point/invalid string fallbacks. This extends the exact-integer handling introduced in #299.

Validation on Windows / Python 3.12:

  • Project-default runtime tests and doctests: 3104 passed, 100% coverage.
  • Ruff checks and formatting checks pass.
  • Mypy checks pass.
  • The new subclass regressions fail against the original implementation.

@dgilland
dgilland merged commit 00ca00a into dgilland:develop Nov 1, 2026
11 checks passed
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — boogu2005:codex/to-integer-subclass-precision into dgilland:develop

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.

3 participants