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: Recursion error comparing set() and collections.Set instances
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: asvetlov, jcea, ncoghlan, python-dev, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2012-10-31 14:33 by ncoghlan, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
abc_set_issuperset_recursion.patch serhiy.storchaka, 2012-10-31 17:01 review
abc_set_issuperset_recursion_2.patch serhiy.storchaka, 2012-10-31 17:54 review
Messages (13)
msg174286 - (view) Author: Nick Coghlan (ncoghlan) * (Python committer) Date: 2012-10-31 14:33
Try these in 3.3 (or Python 3.2 for the latter):

    set() < collections.ChainMap().keys()
    set() < collections.UserDict().keys()

Both fail with max recursion depth exceeded.

Given that both exhibit this behaviour, the core of the problem is quite possibly in MutableMapping.

(Uncovered while attempting to find a tidier ChainMap-based way to implement __subclasshook__ checks for ducktyping based on multiple methods)
msg174294 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-31 15:34
Also:

  {}.keys() < collections.UserDict().keys()
  {}.items() < collections.UserDict().keys()
  {}.items() < collections.UserDict().items()
  ...
msg174295 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-31 15:46
The core of the problem is in Set.

import collections.abc
class S(collections.abc.Set):
    def __contains__(self, key): return False
    def __iter__(self): return iter(())
    def __len__(self): return 0

S() < set() is False.
set() < S() fails.
msg174301 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-31 15:56
Related (if not superseder) issue is issue8743.
msg174329 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-31 17:00
Here is a patch which fixes this particular issue.  Now recursion avoided.  The specified operations raises TypeError.  Fixing this error (if it should be fixed) is the problem of issue8743.
msg174332 - (view) Author: Jesús Cea Avión (jcea) * (Python committer) Date: 2012-10-31 17:05
Serhiy Storchaka, I was wondering if you could provide a test for the testsuite too.
msg174336 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-31 17:23
issue15246 should add a place for such test.  I'm not sure that possible wrong behavior (which can be changed in issue8743) should be perpetuated in the tests.
msg174346 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-10-31 17:54
Patch updated with test which does not rely on set behaviour.
msg174399 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-11-01 11:31
New changeset 8e95a078d490 by Andrew Svetlov in branch '3.2':
Issue #16373: Prevent infinite recursion for ABC Set class operations.
http://hg.python.org/cpython/rev/8e95a078d490

New changeset 11a9297733b8 by Andrew Svetlov in branch '3.3':
Merge issue #16373: Prevent infinite recursion for ABC Set class operations.
http://hg.python.org/cpython/rev/11a9297733b8

New changeset e67c8803cd82 by Andrew Svetlov in branch 'default':
Merge issue #16373: Prevent infinite recursion for ABC Set class operations.
http://hg.python.org/cpython/rev/e67c8803cd82
msg174400 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-11-01 11:33
Fixed. Thanks, Serhiy.
msg205398 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2013-12-06 20:05
This should be backported to Python 2.7 as well.
msg205404 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-12-06 21:24
New changeset 9bf55766d935 by Serhiy Storchaka in branch '2.7':
Issue #16373: Prevent infinite recursion for ABC Set class comparisons.
http://hg.python.org/cpython/rev/9bf55766d935
msg205405 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-12-06 21:25
Done.
History
Date User Action Args
2022-04-11 14:57:37adminsetgithub: 60577
2013-12-06 21:25:14serhiy.storchakasetmessages: + msg205405
versions: + Python 2.7
2013-12-06 21:24:27python-devsetmessages: + msg205404
2013-12-06 20:05:27rhettingersetassignee: rhettinger -> serhiy.storchaka
messages: + msg205398
2012-11-01 11:33:03asvetlovsetstatus: open -> closed

nosy: + asvetlov
messages: + msg174400

resolution: fixed
stage: patch review -> resolved
2012-11-01 11:31:58python-devsetnosy: + python-dev
messages: + msg174399
2012-11-01 05:07:35rhettingersetassignee: rhettinger

nosy: + rhettinger
2012-10-31 17:54:07serhiy.storchakasetfiles: + abc_set_issuperset_recursion_2.patch

messages: + msg174346
2012-10-31 17:23:29serhiy.storchakasetmessages: + msg174336
2012-10-31 17:05:21jceasetmessages: + msg174332
2012-10-31 17:01:25serhiy.storchakasetfiles: + abc_set_issuperset_recursion.patch
keywords: + patch
title: Recursion error comparing set() and MutableMapping.keys() -> Recursion error comparing set() and collections.Set instances
2012-10-31 17:00:06serhiy.storchakasetmessages: + msg174329
stage: patch review
2012-10-31 16:53:40jceasetnosy: + jcea
2012-10-31 15:56:48serhiy.storchakasetmessages: + msg174301
2012-10-31 15:46:04serhiy.storchakasetmessages: + msg174295
2012-10-31 15:34:22serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg174294

components: + Library (Lib)
type: behavior
2012-10-31 14:33:20ncoghlancreate