diff options
author | Beomsoo Kim <beoms424@gmail.com> | 2024-11-19 19:40:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-19 19:40:52 (GMT) |
commit | 8da9920a80c60fb3fc326c623e0f217c84011c1d (patch) | |
tree | d60e93bcdc7fbdf47c46b2f508094d808534776c /Lib/_pydatetime.py | |
parent | 88dc84bcf9fef32afa9af0ab41fa467c9733483f (diff) | |
download | cpython-8da9920a80c60fb3fc326c623e0f217c84011c1d.zip cpython-8da9920a80c60fb3fc326c623e0f217c84011c1d.tar.gz cpython-8da9920a80c60fb3fc326c623e0f217c84011c1d.tar.bz2 |
gh-126947: Typechecking for _pydatetime.timedelta.__new__ arguments (#126949)
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Diffstat (limited to 'Lib/_pydatetime.py')
-rw-r--r-- | Lib/_pydatetime.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/_pydatetime.py b/Lib/_pydatetime.py index 78e03e3..ed01670 100644 --- a/Lib/_pydatetime.py +++ b/Lib/_pydatetime.py @@ -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. |