Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a5ec8753
Commit
a5ec8753
authored
Nov 01, 2012
by
Andrew Svetlov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16373: Prevent infinite recursion for ABC Set class operations.
parent
0221c35a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
Lib/_abcoll.py
Lib/_abcoll.py
+2
-2
Lib/test/test_collections.py
Lib/test/test_collections.py
+33
-0
No files found.
Lib/_abcoll.py
View file @
a5ec8753
...
...
@@ -184,12 +184,12 @@ class Set(Sized, Iterable, Container):
def
__gt__
(
self
,
other
):
if
not
isinstance
(
other
,
Set
):
return
NotImplemented
return
other
<
self
return
other
.
__lt__
(
self
)
def
__ge__
(
self
,
other
):
if
not
isinstance
(
other
,
Set
):
return
NotImplemented
return
other
<=
self
return
other
.
__le__
(
self
)
def
__eq__
(
self
,
other
):
if
not
isinstance
(
other
,
Set
):
...
...
Lib/test/test_collections.py
View file @
a5ec8753
...
...
@@ -651,6 +651,39 @@ class TestCollectionABCs(ABCTestCase):
s
|=
s
self
.
assertEqual
(
s
,
full
)
def
test_issue16373
(
self
):
# Recursion error comparing comparable and noncomparable
# Set instances
class
MyComparableSet
(
Set
):
def
__contains__
(
self
,
x
):
return
False
def
__len__
(
self
):
return
0
def
__iter__
(
self
):
return
iter
([])
class
MyNonComparableSet
(
Set
):
def
__contains__
(
self
,
x
):
return
False
def
__len__
(
self
):
return
0
def
__iter__
(
self
):
return
iter
([])
def
__le__
(
self
,
x
):
return
NotImplemented
def
__lt__
(
self
,
x
):
return
NotImplemented
cs
=
MyComparableSet
()
ncs
=
MyNonComparableSet
()
with
self
.
assertRaises
(
TypeError
):
ncs
<
cs
with
self
.
assertRaises
(
TypeError
):
ncs
<=
cs
with
self
.
assertRaises
(
TypeError
):
cs
>
ncs
with
self
.
assertRaises
(
TypeError
):
cs
>=
ncs
def
test_Mapping
(
self
):
for
sample
in
[
dict
]:
self
.
assertIsInstance
(
sample
(),
Mapping
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment