New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assertion failure in timedelta() in case of bad __divmod__ #75933
Comments
The following code causes an assertion error in timedelta constructor. from datetime import timedelta
class BadInt(int):
def __mul__(self, other):
return Prod()
class Prod:
def __radd__(self, other):
return Sum()
class Sum:
def __divmod__(self, other):
return (0, -1)
timedelta(hours=BadInt(1)) Result: python: /home/serhiy/py/cpython/Modules/_datetimemodule.c:1573: microseconds_to_delta_ex: Assertion `0 <= temp && temp < 1000000' failed. |
I got a different result in latest commit: eeb5ffd ➜ cpython git:(master) ✗ ./python test.py
Traceback (most recent call last):
File "test.py", line 15, in <module>
timedelta(hours=BadInt(1))
SystemError: <class 'datetime.timedelta'> returned NULL without setting an error Do I miss some configure, I'm using ./configure --with-debug |
On Win10, installed 3.5.4, 3.6.3, 3.7.1a1 all raise SystemError. |
Unpatched Python should crash in debug build and can raise SystemError in release build. I can't reproduce a crash on Windows after the patch. |
This patch includes assertions that are easily triggered from user code: https://bugs.python.org/issue35021 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: