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
3f10a952
Commit
3f10a952
authored
Apr 01, 2009
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #5647: MutableSet.__iand__() no longer mutates self during iteration.
parent
0759dd66
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
4 deletions
+30
-4
Lib/_abcoll.py
Lib/_abcoll.py
+3
-4
Lib/test/test_collections.py
Lib/test/test_collections.py
+25
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/_abcoll.py
View file @
3f10a952
...
...
@@ -320,10 +320,9 @@ class MutableSet(Set):
self
.
add
(
value
)
return
self
def
__iand__
(
self
,
c
:
Container
):
for
value
in
self
:
if
value
not
in
c
:
self
.
discard
(
value
)
def
__iand__
(
self
,
it
:
Iterable
):
for
value
in
(
self
-
it
):
self
.
discard
(
value
)
return
self
def
__ixor__
(
self
,
it
:
Iterable
):
...
...
Lib/test/test_collections.py
View file @
3f10a952
...
...
@@ -327,6 +327,25 @@ class TestOneTrickPonyABCs(ABCTestCase):
B
.
register
(
C
)
self
.
failUnless
(
issubclass
(
C
,
B
))
class
WithSet
(
MutableSet
):
def
__init__
(
self
,
it
=
()):
self
.
data
=
set
(
it
)
def
__len__
(
self
):
return
len
(
self
.
data
)
def
__iter__
(
self
):
return
iter
(
self
.
data
)
def
__contains__
(
self
,
item
):
return
item
in
self
.
data
def
add
(
self
,
item
):
self
.
data
.
add
(
item
)
def
discard
(
self
,
item
):
self
.
data
.
discard
(
item
)
class
TestCollectionABCs
(
ABCTestCase
):
...
...
@@ -363,6 +382,12 @@ class TestCollectionABCs(ABCTestCase):
self
.
validate_abstract_methods
(
MutableSet
,
'__contains__'
,
'__iter__'
,
'__len__'
,
'add'
,
'discard'
)
def
test_issue_5647
(
self
):
# MutableSet.__iand__ mutated the set during iteration
s
=
WithSet
(
'abcd'
)
s
&=
WithSet
(
'cdef'
)
# This used to fail
self
.
assertEqual
(
set
(
s
),
set
(
'cd'
))
def
test_issue_4920
(
self
):
# MutableSet.pop() method did not work
class
MySet
(
collections
.
MutableSet
):
...
...
Misc/NEWS
View file @
3f10a952
...
...
@@ -55,6 +55,8 @@ Core and Builtins
Library
-------
- Issue #5647: MutableSet.__iand__() no longer mutates self during iteration.
- Issue #5624: Fix the _winreg module name still used in several modules.
- Issue #5628: Fix io.TextIOWrapper.read() with a unreadable buffer.
...
...
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