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
038ca2a5
Commit
038ca2a5
authored
Aug 13, 2005
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Teach the sets module to correctly compute s-=s and s^=s as the empty set.
parent
f98e6b15
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
Lib/sets.py
Lib/sets.py
+4
-0
Lib/test/test_sets.py
Lib/test/test_sets.py
+13
-0
No files found.
Lib/sets.py
View file @
038ca2a5
...
@@ -480,6 +480,8 @@ class Set(BaseSet):
...
@@ -480,6 +480,8 @@ class Set(BaseSet):
value
=
True
value
=
True
if
not
isinstance
(
other
,
BaseSet
):
if
not
isinstance
(
other
,
BaseSet
):
other
=
Set
(
other
)
other
=
Set
(
other
)
if
self
is
other
:
self
.
clear
()
for
elt
in
other
:
for
elt
in
other
:
if
elt
in
data
:
if
elt
in
data
:
del
data
[
elt
]
del
data
[
elt
]
...
@@ -497,6 +499,8 @@ class Set(BaseSet):
...
@@ -497,6 +499,8 @@ class Set(BaseSet):
data
=
self
.
_data
data
=
self
.
_data
if
not
isinstance
(
other
,
BaseSet
):
if
not
isinstance
(
other
,
BaseSet
):
other
=
Set
(
other
)
other
=
Set
(
other
)
if
self
is
other
:
self
.
clear
()
for
elt
in
ifilter
(
data
.
has_key
,
other
):
for
elt
in
ifilter
(
data
.
has_key
,
other
):
del
data
[
elt
]
del
data
[
elt
]
...
...
Lib/test/test_sets.py
View file @
038ca2a5
...
@@ -243,6 +243,19 @@ class TestBinaryOps(unittest.TestCase):
...
@@ -243,6 +243,19 @@ class TestBinaryOps(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
cmp
,
a
,
12
)
self
.
assertRaises
(
TypeError
,
cmp
,
a
,
12
)
self
.
assertRaises
(
TypeError
,
cmp
,
"abc"
,
a
)
self
.
assertRaises
(
TypeError
,
cmp
,
"abc"
,
a
)
def
test_inplace_on_self
(
self
):
t
=
self
.
set
.
copy
()
t
|=
t
self
.
assertEqual
(
t
,
self
.
set
)
t
&=
t
self
.
assertEqual
(
t
,
self
.
set
)
t
-=
t
self
.
assertEqual
(
len
(
t
),
0
)
t
=
self
.
set
.
copy
()
t
^=
t
self
.
assertEqual
(
len
(
t
),
0
)
#==============================================================================
#==============================================================================
class
TestUpdateOps
(
unittest
.
TestCase
):
class
TestUpdateOps
(
unittest
.
TestCase
):
...
...
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