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
f434f5b8
Kaydet (Commit)
f434f5b8
authored
Haz 27, 2018
tarafından
Chris Jerdonek
Kaydeden (comit)
Tim Graham
Haz 27, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #29253 -- Fixed method_decorator() crash if decorator sets a new attribute.
Regression in
fdc936c9
.
üst
f52b0261
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
3 deletions
+20
-3
decorators.py
django/utils/decorators.py
+5
-3
tests.py
tests/decorators/tests.py
+15
-0
No files found.
django/utils/decorators.py
Dosyayı görüntüle @
f434f5b8
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
# For backwards compatibility in Django 2.0.
# For backwards compatibility in Django 2.0.
from
contextlib
import
ContextDecorator
# noqa
from
contextlib
import
ContextDecorator
# noqa
from
functools
import
WRAPPER_ASSIGNMENTS
,
update_wrapper
,
wraps
from
functools
import
WRAPPER_ASSIGNMENTS
,
partial
,
update_wrapper
,
wraps
class
classonlymethod
(
classmethod
):
class
classonlymethod
(
classmethod
):
...
@@ -36,8 +36,10 @@ def _multi_decorate(decorators, method):
...
@@ -36,8 +36,10 @@ def _multi_decorate(decorators, method):
def
_wrapper
(
self
,
*
args
,
**
kwargs
):
def
_wrapper
(
self
,
*
args
,
**
kwargs
):
# bound_method has the signature that 'decorator' expects i.e. no
# bound_method has the signature that 'decorator' expects i.e. no
# 'self' argument.
# 'self' argument, but it's a closure over self so it can call
bound_method
=
method
.
__get__
(
self
,
type
(
self
))
# 'func'. Also, wrap method.__get__() in a function because new
# attributes can't be set on bound method objects, only on functions.
bound_method
=
partial
(
method
.
__get__
(
self
,
type
(
self
)))
for
dec
in
decorators
:
for
dec
in
decorators
:
bound_method
=
dec
(
bound_method
)
bound_method
=
dec
(
bound_method
)
return
bound_method
(
*
args
,
**
kwargs
)
return
bound_method
(
*
args
,
**
kwargs
)
...
...
tests/decorators/tests.py
Dosyayı görüntüle @
f434f5b8
...
@@ -271,6 +271,21 @@ class MethodDecoratorTests(SimpleTestCase):
...
@@ -271,6 +271,21 @@ class MethodDecoratorTests(SimpleTestCase):
self
.
assertEqual
(
Test
.
method
.
__doc__
,
'A method'
)
self
.
assertEqual
(
Test
.
method
.
__doc__
,
'A method'
)
self
.
assertEqual
(
Test
.
method
.
__name__
,
'method'
)
self
.
assertEqual
(
Test
.
method
.
__name__
,
'method'
)
def
test_new_attribute
(
self
):
"""A decorator that sets a new attribute on the method."""
def
decorate
(
func
):
func
.
x
=
1
return
func
class
MyClass
:
@method_decorator
(
decorate
)
def
method
(
self
):
return
True
obj
=
MyClass
()
self
.
assertEqual
(
obj
.
method
.
x
,
1
)
self
.
assertIs
(
obj
.
method
(),
True
)
def
test_bad_iterable
(
self
):
def
test_bad_iterable
(
self
):
decorators
=
{
myattr_dec_m
,
myattr2_dec_m
}
decorators
=
{
myattr_dec_m
,
myattr2_dec_m
}
msg
=
"'set' object is not subscriptable"
msg
=
"'set' object is not subscriptable"
...
...
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