-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
Fatal error in type union #88649
Comments
The following example crashes: class TypeVar:
@property
def __module__(self):
1/0 str | TypeVar() Output:
Fatal Python error: _Py_CheckSlotResult: Slot | of type type succeeded with an exception set
Python runtime state: initialized
Traceback (most recent call last):
File "<stdin>", line 4, in __module__
ZeroDivisionError: division by zero
Aborted (core dumped) The problem in Objects/unionobject.c is that is_typing_module() (and therefore is_typevar() and is_special_form()) can return not only 0 and 1, but -1 as a signal of error, but is_unionable() does not check results for error and interprets it as boolean true. |
A possible simple fix is to change these lines https://github.com/python/cpython/blob/main/Objects/unionobject.c#L294-L301 to:
However, that may slow down union a little since we lose the short-circuiting that Checking each result individually and mimicking the short circuiting behavior works too, so I did that. What do you think Serhiy? |
Yes, Checking each result individually is a right way. Not only because performance, but because calling any Python code while an error is set will cause a crash in debug build and weird bugs in release build. It is better to return as fast as you have an error. Thank you for your PR Ken Jin. |
Oh, that's a good point too. Thanks for the explanation, reviews and merge Serhiy. |
__module__
#26848__module__
(GH-26848) #26852Note: 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: