mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-126947: Typechecking for _pydatetime.timedelta.__new__ arguments (#126949)
Co-authored-by: sobolevn <mail@sobolevn.me> Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
This commit is contained in:
parent
88dc84bcf9
commit
8da9920a80
3 changed files with 25 additions and 1 deletions
|
@ -651,7 +651,19 @@ class timedelta:
|
|||
# guide the C implementation; it's way more convoluted than speed-
|
||||
# ignoring auto-overflow-to-long idiomatic Python could be.
|
||||
|
||||
# XXX Check that all inputs are ints or floats.
|
||||
for name, value in (
|
||||
("days", days),
|
||||
("seconds", seconds),
|
||||
("microseconds", microseconds),
|
||||
("milliseconds", milliseconds),
|
||||
("minutes", minutes),
|
||||
("hours", hours),
|
||||
("weeks", weeks)
|
||||
):
|
||||
if not isinstance(value, (int, float)):
|
||||
raise TypeError(
|
||||
f"unsupported type for timedelta {name} component: {type(value).__name__}"
|
||||
)
|
||||
|
||||
# Final values, all integer.
|
||||
# s and us fit in 32-bit signed ints; d isn't bounded.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue