Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
f4ee1c23
Kaydet (Commit)
f4ee1c23
authored
Eyl 29, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #22609: Constructor of collections.UserDict now accepts the self keyword
argument.
üst
3066fc41
68f5ef22
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
2 deletions
+45
-2
__init__.py
Lib/collections/__init__.py
+16
-1
test_userdict.py
Lib/test/test_userdict.py
+26
-1
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/collections/__init__.py
Dosyayı görüntüle @
f4ee1c23
...
...
@@ -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"
,
PendingDeprecationWarning
,
stacklevel
=
2
)
else
:
dict
=
None
self
.
data
=
{}
if
dict
is
not
None
:
self
.
update
(
dict
)
...
...
Lib/test/test_userdict.py
Dosyayı görüntüle @
f4ee1c23
...
...
@@ -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
(
PendingDeprecationWarning
,
"'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
(
PendingDeprecationWarning
,
"'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
Dosyayı görüntüle @
f4ee1c23
...
...
@@ -21,6 +21,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