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
1c746c28
Commit
1c746c28
authored
Apr 15, 2011
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix minor subclassing issue with collections.Counter
parent
181810b5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
2 deletions
+13
-2
Lib/collections.py
Lib/collections.py
+2
-2
Lib/test/test_collections.py
Lib/test/test_collections.py
+9
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/collections.py
View file @
1c746c28
...
...
@@ -459,8 +459,8 @@ class Counter(dict):
self
.
update
(
kwds
)
def
copy
(
self
):
'
Like dict.copy() but returns a Counter instance instead of a dict
.'
return
Counter
(
self
)
'
Return a shallow copy
.'
return
self
.
__class__
(
self
)
def
__reduce__
(
self
):
return
self
.
__class__
,
(
dict
(
self
),)
...
...
Lib/test/test_collections.py
View file @
1c746c28
...
...
@@ -680,6 +680,15 @@ class TestCounter(unittest.TestCase):
self
.
assertEqual
(
len
(
dup
),
len
(
words
))
self
.
assertEqual
(
type
(
dup
),
type
(
words
))
def
test_copy_subclass
(
self
):
class
MyCounter
(
Counter
):
pass
c
=
MyCounter
(
'slartibartfast'
)
d
=
c
.
copy
()
self
.
assertEqual
(
d
,
c
)
self
.
assertEqual
(
len
(
d
),
len
(
c
))
self
.
assertEqual
(
type
(
d
),
type
(
c
))
def
test_conversions
(
self
):
# Convert to: set, list, dict
s
=
'she sells sea shells by the sea shore'
...
...
Misc/NEWS
View file @
1c746c28
...
...
@@ -58,6 +58,8 @@ Library
- Issue #11467: Fix urlparse behavior when handling urls which contains scheme
specific part only digits. Patch by Santoso Wijaya.
- collections.Counter().copy() now works correctly for subclasses.
- Issue #11474: Fix the bug with url2pathname() handling of '/C|/' on Windows.
Patch by Santoso Wijaya.
...
...
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