File tree 3 files changed +35
-2
lines changed
3 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,9 @@ def non_member_attributes(defaults, members):
52
52
# staticmethods can't use attributes of the interface.
53
53
continue
54
54
55
+ elif isinstance (impl , property ):
56
+ impl = impl .fget
57
+
55
58
self_name = TypedSignature (impl ).first_argument_name
56
59
if self_name is None :
57
60
# No parameters.
@@ -73,13 +76,20 @@ def accessed_attributes_of_local(f, local_name):
73
76
The analysis performed by this function is conservative, meaning that
74
77
it's not guaranteed to find **all** attributes used.
75
78
"""
79
+ try :
80
+ instrs = dis .get_instructions (f )
81
+ except TypeError :
82
+ # Got a default wrapping an object that's not a python function. Be
83
+ # conservative and assume this is safe.
84
+ return set ()
85
+
76
86
used = set ()
77
87
# Find sequences of the form: LOAD_FAST(local_name), LOAD_ATTR(<name>).
78
88
# This will find all usages of the form ``local_name.<name>``.
79
89
#
80
90
# It will **NOT** find usages in which ``local_name`` is aliased to
81
91
# another name.
82
- for first , second in sliding_window (dis . get_instructions ( f ) , 2 ):
92
+ for first , second in sliding_window (instrs , 2 ):
83
93
if first .opname == 'LOAD_FAST' and first .argval == local_name :
84
94
if second .opname in ('LOAD_ATTR' , 'LOAD_METHOD' , 'STORE_ATTR' ):
85
95
used .add (second .argval )
Original file line number Diff line number Diff line change @@ -528,6 +528,29 @@ def method2(self):
528
528
assert C ().has_default () == 3
529
529
530
530
531
+ def test_default_property ():
532
+
533
+ class IFace (Interface ): # pragma: nocover
534
+
535
+ @default
536
+ @property
537
+ def default_prop (self ):
538
+ return True
539
+
540
+ class C (implements (IFace )): # pragma: nocover
541
+ pass
542
+
543
+ assert C ().default_prop
544
+
545
+ class D (implements (IFace )):
546
+
547
+ @property
548
+ def default_prop (self ):
549
+ return False
550
+
551
+ assert not D ().default_prop
552
+
553
+
531
554
def test_override_default ():
532
555
533
556
class IFace (Interface ): # pragma: nocover
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def install_requires():
30
30
31
31
setup (
32
32
name = 'python-interface' ,
33
- version = '1.5.0 ' ,
33
+ version = '1.5.2 ' ,
34
34
description = "Pythonic Interface definitions" ,
35
35
author = "Scott Sanderson" ,
36
36
author_email = "scott.b.sanderson90@gmail.com" ,
You can’t perform that action at this time.
0 commit comments