Skip to content

Commit dad8d36

Browse files
author
Scott Sanderson
committed
ENH: Check STORE_ATTR in default warnings.
1 parent ebd2504 commit dad8d36

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

interface/default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def accessed_attributes_of_local(f, local_name):
8181
# another name.
8282
for first, second in sliding_window(dis.get_instructions(f), 2):
8383
if first.opname == 'LOAD_FAST' and first.argval == local_name:
84-
if second.opname == 'LOAD_ATTR':
84+
if second.opname in ('LOAD_ATTR', 'STORE_ATTR'):
8585
used.add(second.argval)
8686
return used
8787

interface/tests/test_interface.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,23 @@ def foo(self, a, b):
596596

597597
@default
598598
def probably_broken_method_with_no_args():
599-
pass # This eex
599+
# This is a weird thing to do, but it shouldn't cause us to
600+
# crash because of missing a first parameter.
601+
pass
602+
603+
@default
604+
@classmethod
605+
def probably_broken_classmethod_with_no_args():
606+
# This is a weird thing to do, but it shouldn't cause us to
607+
# crash because of missing a first parameter.
608+
pass
609+
610+
@default
611+
@property
612+
def probably_broken_property_with_no_args():
613+
# This is a weird thing to do, but it shouldn't cause us to
614+
# crash because of missing a first parameter.
615+
pass
600616

601617
@default
602618
@staticmethod
@@ -609,6 +625,7 @@ def default_staticmethod():
609625
def default_method(self, x):
610626
foo = self.foo(1, 2) # Should be fine.
611627
wut = self.not_in_interface(2, 3) # Should cause a warning.
628+
self.setting_non_interface = 2 # Should cause a warning.
612629
return foo + wut
613630

614631
@default
@@ -635,6 +652,7 @@ def default_classmethod(cls, x):
635652
636653
The following attributes may be accessed but are not part of the interface:
637654
- not_in_interface
655+
- setting_non_interface
638656
639657
Consider changing the implementation of default_method or making these attributes part of HasDefault.""" # noqa
640658
assert second == expected_second

0 commit comments

Comments
 (0)