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
5527cf11
Commit
5527cf11
authored
Sep 29, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #22609: Constructor of collections.UserDict now accepts the self keyword
argument.
parents
87b93fe3
f4ee1c23
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
2 deletions
+45
-2
Lib/collections/__init__.py
Lib/collections/__init__.py
+16
-1
Lib/test/test_userdict.py
Lib/test/test_userdict.py
+26
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/collections/__init__.py
View file @
5527cf11
...
...
@@ -939,7 +939,22 @@ class ChainMap(MutableMapping):
class
UserDict
(
MutableMapping
):
# Start by filling-out the abstract methods
def
__init__
(
self
,
dict
=
None
,
**
kwargs
):
def
__init__
(
*
args
,
**
kwargs
):
if
not
args
:
raise
TypeError
(
"descriptor '__init__' of 'UserDict' object "
"needs an argument"
)
self
,
*
args
=
args
if
len
(
args
)
>
1
:
raise
TypeError
(
'expected at most 1 arguments, got %d'
%
len
(
args
))
if
args
:
dict
=
args
[
0
]
elif
'dict'
in
kwargs
:
dict
=
kwargs
.
pop
(
'dict'
)
import
warnings
warnings
.
warn
(
"Passing 'dict' as keyword argument is deprecated"
,
DeprecationWarning
,
stacklevel
=
2
)
else
:
dict
=
None
self
.
data
=
{}
if
dict
is
not
None
:
self
.
update
(
dict
)
...
...
Lib/test/test_userdict.py
View file @
5527cf11
...
...
@@ -29,7 +29,8 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol):
self
.
assertEqual
(
collections
.
UserDict
(
one
=
1
,
two
=
2
),
d2
)
# item sequence constructor
self
.
assertEqual
(
collections
.
UserDict
([(
'one'
,
1
),
(
'two'
,
2
)]),
d2
)
self
.
assertEqual
(
collections
.
UserDict
(
dict
=
[(
'one'
,
1
),
(
'two'
,
2
)]),
d2
)
with
self
.
assertWarnsRegex
(
DeprecationWarning
,
"'dict'"
):
self
.
assertEqual
(
collections
.
UserDict
(
dict
=
[(
'one'
,
1
),
(
'two'
,
2
)]),
d2
)
# both together
self
.
assertEqual
(
collections
.
UserDict
([(
'one'
,
1
),
(
'two'
,
2
)],
two
=
3
,
three
=
5
),
d3
)
...
...
@@ -139,6 +140,30 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol):
self
.
assertEqual
(
t
.
popitem
(),
(
"x"
,
42
))
self
.
assertRaises
(
KeyError
,
t
.
popitem
)
def
test_init
(
self
):
for
kw
in
'self'
,
'other'
,
'iterable'
:
self
.
assertEqual
(
list
(
collections
.
UserDict
(
**
{
kw
:
42
}).
items
()),
[(
kw
,
42
)])
self
.
assertEqual
(
list
(
collections
.
UserDict
({},
dict
=
42
).
items
()),
[(
'dict'
,
42
)])
self
.
assertEqual
(
list
(
collections
.
UserDict
({},
dict
=
None
).
items
()),
[(
'dict'
,
None
)])
with
self
.
assertWarnsRegex
(
DeprecationWarning
,
"'dict'"
):
self
.
assertEqual
(
list
(
collections
.
UserDict
(
dict
=
{
'a'
:
42
}).
items
()),
[(
'a'
,
42
)])
self
.
assertRaises
(
TypeError
,
collections
.
UserDict
,
42
)
self
.
assertRaises
(
TypeError
,
collections
.
UserDict
,
(),
())
self
.
assertRaises
(
TypeError
,
collections
.
UserDict
.
__init__
)
def
test_update
(
self
):
for
kw
in
'self'
,
'dict'
,
'other'
,
'iterable'
:
d
=
collections
.
UserDict
()
d
.
update
(
**
{
kw
:
42
})
self
.
assertEqual
(
list
(
d
.
items
()),
[(
kw
,
42
)])
self
.
assertRaises
(
TypeError
,
collections
.
UserDict
().
update
,
42
)
self
.
assertRaises
(
TypeError
,
collections
.
UserDict
().
update
,
{},
{})
self
.
assertRaises
(
TypeError
,
collections
.
UserDict
.
update
)
def
test_missing
(
self
):
# Make sure UserDict doesn't have a __missing__ method
self
.
assertEqual
(
hasattr
(
collections
.
UserDict
,
"__missing__"
),
False
)
...
...
Misc/NEWS
View file @
5527cf11
...
...
@@ -190,6 +190,9 @@ Core and Builtins
Library
-------
- Issue #22609: Constructor of collections.UserDict now accepts the self keyword
argument.
- Issue #25111: Fixed comparison of traceback.FrameSummary.
- Issue #25262. Added support for BINBYTES8 opcode in Python implementation of
...
...
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