[issue44483] Fatal error in type union

2021-06-23 Thread Ken Jin


Ken Jin  added the comment:

Oh, that's a good point too. Thanks for the explanation, reviews and merge 
Serhiy.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44483] Fatal error in type union

2021-06-23 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

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.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44483] Fatal error in type union

2021-06-23 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset 7e6cad7e303b3991360a0fe332b0d21aa0f6fe5e by Miss Islington (bot) 
in branch '3.10':
bpo-44483: Fix crash in union object with bad ``__module__`` (GH-26848) 
(GH-26852)
https://github.com/python/cpython/commit/7e6cad7e303b3991360a0fe332b0d21aa0f6fe5e


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44483] Fatal error in type union

2021-06-22 Thread miss-islington


Change by miss-islington :


--
nosy: +miss-islington
nosy_count: 2.0 -> 3.0
pull_requests: +25433
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26852

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44483] Fatal error in type union

2021-06-22 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:


New changeset adfa1ba398c74720b42f16f06fd3ec0353599fa5 by Ken Jin in branch 
'main':
bpo-44483: Fix crash in union object with bad ``__module__`` (GH-26848)
https://github.com/python/cpython/commit/adfa1ba398c74720b42f16f06fd3ec0353599fa5


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44483] Fatal error in type union

2021-06-22 Thread Ken Jin


Ken Jin  added the comment:

A possible simple fix is to change these lines 
https://github.com/python/cpython/blob/main/Objects/unionobject.c#L294-L301

to:
```
return (
is_typevar(obj) |
is_new_type(obj) |
is_special_form(obj) |
PyType_Check(obj) |
PyObject_TypeCheck(obj, _GenericAliasType) |
(int)(type == &_Py_UnionType));
```

However, that may slow down union a little since we lose the short-circuiting 
that `||` provides over `|`, and all checks have to be evaluated.

Checking each result individually and mimicking the short circuiting behavior 
works too, so I did that. What do you think Serhiy?

--
stage: patch review -> 

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44483] Fatal error in type union

2021-06-22 Thread Ken Jin


Change by Ken Jin :


--
keywords: +patch
nosy: +kj
nosy_count: 1.0 -> 2.0
pull_requests: +25429
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26848

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44483] Fatal error in type union

2021-06-22 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

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 "", 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.

--
assignee: serhiy.storchaka
components: Interpreter Core
messages: 396307
nosy: serhiy.storchaka
priority: normal
severity: normal
status: open
title: Fatal error in type union
type: crash
versions: Python 3.10, Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com