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
cab4566c
Kaydet (Commit)
cab4566c
authored
Eyl 29, 2015
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #22609: Constructor and the update method of collections.UserDict now
accept the self keyword argument.
üst
22afc506
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
3 deletions
+72
-3
UserDict.py
Lib/UserDict.py
+35
-2
test_userdict.py
Lib/test/test_userdict.py
+34
-1
NEWS
Misc/NEWS
+3
-0
No files found.
Lib/UserDict.py
Dosyayı görüntüle @
cab4566c
"""A more or less complete user-defined wrapper around dictionary objects."""
class
UserDict
:
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
[
0
]
args
=
args
[
1
:]
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
)
...
...
@@ -43,7 +60,23 @@ class UserDict:
def
itervalues
(
self
):
return
self
.
data
.
itervalues
()
def
values
(
self
):
return
self
.
data
.
values
()
def
has_key
(
self
,
key
):
return
key
in
self
.
data
def
update
(
self
,
dict
=
None
,
**
kwargs
):
def
update
(
*
args
,
**
kwargs
):
if
not
args
:
raise
TypeError
(
"descriptor 'update' of 'UserDict' object "
"needs an argument"
)
self
=
args
[
0
]
args
=
args
[
1
:]
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
if
dict
is
None
:
pass
elif
isinstance
(
dict
,
UserDict
):
...
...
Lib/test/test_userdict.py
Dosyayı görüntüle @
cab4566c
...
...
@@ -2,6 +2,7 @@
from
test
import
test_support
,
mapping_tests
import
UserDict
import
warnings
d0
=
{}
d1
=
{
"one"
:
1
}
...
...
@@ -29,7 +30,9 @@ class UserDictTest(mapping_tests.TestHashMappingProtocol):
self
.
assertEqual
(
UserDict
.
UserDict
(
one
=
1
,
two
=
2
),
d2
)
# item sequence constructor
self
.
assertEqual
(
UserDict
.
UserDict
([(
'one'
,
1
),
(
'two'
,
2
)]),
d2
)
self
.
assertEqual
(
UserDict
.
UserDict
(
dict
=
[(
'one'
,
1
),
(
'two'
,
2
)]),
d2
)
with
test_support
.
check_warnings
((
".*'dict'.*"
,
PendingDeprecationWarning
)):
self
.
assertEqual
(
UserDict
.
UserDict
(
dict
=
[(
'one'
,
1
),
(
'two'
,
2
)]),
d2
)
# both together
self
.
assertEqual
(
UserDict
.
UserDict
([(
'one'
,
1
),
(
'two'
,
2
)],
two
=
3
,
three
=
5
),
d3
)
...
...
@@ -148,6 +151,36 @@ 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
(
UserDict
.
UserDict
(
**
{
kw
:
42
})
.
items
()),
[(
kw
,
42
)])
self
.
assertEqual
(
list
(
UserDict
.
UserDict
({},
dict
=
42
)
.
items
()),
[(
'dict'
,
42
)])
self
.
assertEqual
(
list
(
UserDict
.
UserDict
({},
dict
=
None
)
.
items
()),
[(
'dict'
,
None
)])
with
test_support
.
check_warnings
((
".*'dict'.*"
,
PendingDeprecationWarning
)):
self
.
assertEqual
(
list
(
UserDict
.
UserDict
(
dict
=
{
'a'
:
42
})
.
items
()),
[(
'a'
,
42
)])
self
.
assertRaises
(
TypeError
,
UserDict
.
UserDict
,
42
)
self
.
assertRaises
(
TypeError
,
UserDict
.
UserDict
,
(),
())
self
.
assertRaises
(
TypeError
,
UserDict
.
UserDict
.
__init__
)
def
test_update
(
self
):
for
kw
in
'self'
,
'other'
,
'iterable'
:
d
=
UserDict
.
UserDict
()
d
.
update
(
**
{
kw
:
42
})
self
.
assertEqual
(
list
(
d
.
items
()),
[(
kw
,
42
)])
d
=
UserDict
.
UserDict
()
with
test_support
.
check_warnings
((
".*'dict'.*"
,
PendingDeprecationWarning
)):
d
.
update
(
dict
=
{
'a'
:
42
})
self
.
assertEqual
(
list
(
d
.
items
()),
[(
'a'
,
42
)])
self
.
assertRaises
(
TypeError
,
UserDict
.
UserDict
()
.
update
,
42
)
self
.
assertRaises
(
TypeError
,
UserDict
.
UserDict
()
.
update
,
{},
{})
self
.
assertRaises
(
TypeError
,
UserDict
.
UserDict
.
update
)
def
test_missing
(
self
):
# Make sure UserDict doesn't have a __missing__ method
self
.
assertEqual
(
hasattr
(
UserDict
,
"__missing__"
),
False
)
...
...
Misc/NEWS
Dosyayı görüntüle @
cab4566c
...
...
@@ -37,6 +37,9 @@ Core and Builtins
Library
-------
- Issue #22609: Constructor and the update method of collections.UserDict now
accept the self keyword argument.
- Issue #25203: Failed readline.set_completer_delims() no longer left the
module in inconsistent state.
...
...
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