This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: typing.Union raises RecursionError when comparing Union to other type
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: levkivskyi Nosy List: gvanrossum, levkivskyi, spiside
Priority: normal Keywords: patch

Created on 2017-01-11 23:03 by spiside, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
spirowork.patch spiside, 2017-01-11 23:03 Patch review
Messages (3)
msg285279 - (view) Author: Spiro Sideris (spiside) * Date: 2017-01-11 23:03
The typing.Union module raises a RecursionError when comparing a Union with no additional tree_args to a type that is not a Union.

An example of the stack trace with the added test looks like the following:

0:00:00 [1/1] test_typing
test test_typing failed -- Traceback (most recent call last):
  File "/Users/spiro/Development/open_source/cpython/Lib/test/test_typing.py", line 221, in test_union_compare_other
    self.assertNotEqual(Union, object)
  File "/Users/spiro/Development/open_source/cpython/Lib/unittest/case.py", line 827, in assertNotEqual
    if not first != second:
  File "/Users/spiro/Development/open_source/cpython/Lib/typing.py", line 760, in __eq__
    return self._subs_tree() == other#return self._subs_tree() is not self and self._subs_tree() == other
  File "/Users/spiro/Development/open_source/cpython/Lib/typing.py", line 760, in __eq__
    return self._subs_tree() == other#return self._subs_tree() is not self and self._subs_tree() == other
  File "/Users/spiro/Development/open_source/cpython/Lib/typing.py", line 760, in __eq__
    return self._subs_tree() == other#return self._subs_tree() is not self and self._subs_tree() == other
  [Previous line repeated 233 more times]
  File "/Users/spiro/Development/open_source/cpython/Lib/typing.py", line 759, in __eq__
    if not isinstance(other, _Union):
RecursionError: maximum recursion depth exceeded in __instancecheck__

test_typing failed

1 test failed:
    test_typing

Total duration: 316 ms
Tests result: FAILURE

The test compares a Union with no tree_args to another type.
msg285350 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2017-01-12 21:50
Thank you for catching this corner case!

I have made a PR upstream based on your patch: https://github.com/python/typing/pull/350

As I understand the fix will go in 3.6.1 and 3.5.4
msg285700 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2017-01-18 04:48
Fixed, see http://bugs.python.org/issue28556#msg281317

New changeset 75c7bc2c1ad8 by Guido van Rossum in branch '3.5':
Issue #28556: upstream improvements to docstrings and error messages by Ivan Levkivskyi (#331)
https://hg.python.org/cpython/rev/75c7bc2c1ad8

New changeset 294525aac5eb by Guido van Rossum in branch '3.6':
Issue #28556: upstream improvements to docstrings and error messages by Ivan Levkivskyi (#331) (3.5->3.6)
https://hg.python.org/cpython/rev/294525aac5eb

New changeset 30f154d9abf0 by Guido van Rossum in branch 'default':
Issue #28556: upstream improvements to docstrings and error messages by Ivan Levkivskyi (#331) (3.6->3.7)
https://hg.python.org/cpython/rev/30f154d9abf0
History
Date User Action Args
2022-04-11 14:58:41adminsetgithub: 73432
2017-01-18 04:48:54gvanrossumsetstatus: open -> closed
resolution: fixed
messages: + msg285700
2017-01-12 21:50:19levkivskyisetmessages: + msg285350
2017-01-12 18:14:40gvanrossumsetassignee: levkivskyi

nosy: + levkivskyi
2017-01-12 13:18:12berker.peksagsetnosy: + gvanrossum

stage: patch review
2017-01-12 04:00:54Jim Fasarakis-Hilliardsettype: crash -> behavior
versions: - Python 2.7, Python 3.3, Python 3.4
2017-01-11 23:03:00spisidecreate