Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
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
django
Commits
aa01c99f
Kaydet (Commit)
aa01c99f
authored
Agu 18, 2013
tarafından
Alex Gaynor
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge pull request #1479 from nickbruun/ticket_20924
Proxy __len__ and __contains__ for LazyObject
üst
c2907a6e
7a698c05
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
+16
-0
functional.py
django/utils/functional.py
+3
-0
test_simplelazyobject.py
tests/utils_tests/test_simplelazyobject.py
+13
-0
No files found.
django/utils/functional.py
Dosyayı görüntüle @
aa01c99f
...
...
@@ -270,6 +270,9 @@ class LazyObject(object):
def
__delitem__
(
self
,
key
):
del
self
[
key
]
__len__
=
new_method_proxy
(
len
)
__contains__
=
new_method_proxy
(
operator
.
contains
)
# Workaround for http://bugs.python.org/issue12370
_super
=
super
...
...
tests/utils_tests/test_simplelazyobject.py
Dosyayı görüntüle @
aa01c99f
...
...
@@ -136,6 +136,9 @@ class TestUtilsSimpleLazyObject(TestCase):
self
.
assertEqual
(
lazydict
[
'one'
],
1
)
lazydict
[
'one'
]
=
-
1
self
.
assertEqual
(
lazydict
[
'one'
],
-
1
)
self
.
assertTrue
(
'one'
in
lazydict
)
self
.
assertFalse
(
'two'
in
lazydict
)
self
.
assertEqual
(
len
(
lazydict
),
1
)
del
lazydict
[
'one'
]
with
self
.
assertRaises
(
KeyError
):
lazydict
[
'one'
]
...
...
@@ -183,3 +186,13 @@ class TestUtilsSimpleLazyObject(TestCase):
# This would fail with "TypeError: expected string or Unicode object, NoneType found".
pickled
=
cPickle
.
dumps
(
x
)
def
test_list_set
(
self
):
lazy_list
=
SimpleLazyObject
(
lambda
:
[
1
,
2
,
3
,
4
,
5
])
lazy_set
=
SimpleLazyObject
(
lambda
:
set
([
1
,
2
,
3
,
4
]))
self
.
assertTrue
(
1
in
lazy_list
)
self
.
assertTrue
(
1
in
lazy_set
)
self
.
assertFalse
(
6
in
lazy_list
)
self
.
assertFalse
(
6
in
lazy_set
)
self
.
assertEqual
(
len
(
lazy_list
),
5
)
self
.
assertEqual
(
len
(
lazy_set
),
4
)
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