8 Commits
Author SHA1 Message Date
Jeongseop Lim 7b58a8980d Reject extra positional arguments to float() (#8509)
* Reject extra positional arguments to float()

PyFloat::slot_new's exact-float fast path tested args.args.first(), which
succeeds for any number of positional arguments, so float(1.5, True)
returned the first one and never reached args.bind(vm). CPython's clinic
generated float_new runs _PyArg_CheckPositional("float", nargs, 0, 1)
before it fetches the first argument.

Add args.args.len() == 1 to the condition, as PyInt::slot_new,
PyStr::slot_new and PyComplex::slot_new already do; the extra argument
then falls through to args.bind(vm) and raises TypeError.

Assisted-by: Claude Code:claude-opus-5

* Bind float() arguments before the fast path

The exact-float fast path repeated float()'s argument count inline, which
duplicates what FromArgs::arity already knows. Bind first and match on the
resulting OptionalArg instead, so the positional and keyword rules stay in
one place and the bound value is reused by py_new.

Assisted-by: Claude Code:claude-opus-5
2026-08-13 23:32:19 +09:00
Jeong, YunWon 8e30b94eef literal: round-half-even tie for normal-range float/complex repr (#8243)
to_string's normal-magnitude branch and complex::component_to_string
returned Rust's shortest formatting directly, which can pick the odd-digit
neighbour of a rounding tie where repr() picks the even one (e.g. bits
0x42e26687db6b9b04 formats as 161852602146008.13 vs repr's ...08.12).
Route both through prefer_cpython_tie_repr, generalized to fixed-notation
strings. Add unit tests and float/complex repr snippet tests.

Assisted-by: Claude
2026-07-09 21:42:08 +09:00
Changjoon bc29e21a9d Drop redundant exception type prefix from float-to-int error messages (#7763)
CPython raises `OverflowError("cannot convert float infinity to integer")`
and `ValueError("cannot convert float NaN to integer")` from
`Objects/floatobject.c::float___trunc___impl` and friends. The exception
type name is added by Python's traceback display layer; the message
itself should not duplicate it.

`try_to_bigint` was producing
`OverflowError("OverflowError: cannot convert ...")` etc., which made
`repr(e)` and any code path that inspects `str(e)` diverge from CPython.

Affects all 5 callers of `try_to_bigint`: `__int__`, `__floor__`,
`__ceil__`, `__round__` (no-arg), `__trunc__` — i.e. `int(x)`,
`math.floor/ceil/trunc(x)`, `round(x)` for non-finite floats.

Verified byte-identical with CPython 3.14.4 across 14 affected sites.
2026-05-04 10:24:08 +09:00
black formatter 865c4984f6 format tests with black 2023-03-05 22:34:55 +09:00
Jeong YunWon 987ad12181 relocate int-unrelated tests to proper files 2023-03-05 22:34:55 +09:00
yt2b 3d52769a47 Add tests 2023-01-22 14:44:35 +09:00
Gyubong e8ed8aab9f Fix PyFloat::py_new always returning new float object issue (#3979) 2022-08-01 01:52:15 +09:00
Jeong Yunwon 487cd56391 rename extra_tests files 2022-05-04 00:53:20 +09:00