Skip to content

Commit

Permalink
Merge branch 'v3.3.2'
Browse files Browse the repository at this point in the history
# Conflicts:
#	tests/test_implementation_checks.py
  • Loading branch information
Tim Mitchell committed Aug 1, 2019
2 parents b3a5835 + 23406e5 commit 7c0215e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pure_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def __new__(mcs, clsname, bases, attributes, **kwargs):
attribute_names, method_signatures = _get_abc_interface_props_and_funcs(base)
interface_method_signatures.update(method_signatures)
interface_attribute_names.update(attribute_names)
elif not issubclass(base, PureInterface) and is_development:
elif is_development and not issubclass(base, PureInterface):
_check_method_signatures(base.__dict__, base.__name__, interface_method_signatures)

if is_development:
Expand All @@ -536,13 +536,17 @@ def __new__(mcs, clsname, bases, attributes, **kwargs):
'Did you forget to inherit from object to make the class concrete?'.format(func.__name__))
else: # concrete sub-type
namespace = attributes
class_properties = set(k for k, v in namespace.items() if _is_descriptor(v))
class_properties = set()
for bt, is_interface in base_types:
if not is_interface:
class_properties |= set(k for k, v in bt.__dict__.items() if _is_descriptor(v))
class_properties |= set(k for k, v in namespace.items() if _is_descriptor(v))
abstract_properties.difference_update(class_properties)
partial_implementation = 'pi_partial_implementation' in namespace
if partial_implementation:
value = namespace.pop('pi_partial_implementation')
if not value:
warnings.warn('Partial implmentation is indicated by presence of '
warnings.warn('Partial implementation is indicated by presence of '
'pi_partial_implementation attribute, not it''s value')

# create class
Expand Down
18 changes: 17 additions & 1 deletion tests/test_implementation_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
except ImportError:
import mock

class ADescriptor(object):
def __init__(self, value):
self._value = value

def __get__(self, instance, owner):
return self._value


class IAnimal(PureInterface):
@abstractproperty
Expand Down Expand Up @@ -260,7 +267,16 @@ class SimpleSimon(object, ISimple):
pi_partial_implementation = False

self.assertEqual(warn.call_count, 1)
self.assertTrue(warn.call_args[0][0].startswith('Partial implmentation is indicated'))
self.assertTrue(warn.call_args[0][0].startswith('Partial implementation is indicated'))

def test_super_class_properties_detected(self):
class HeightDescr(object):
height = ADescriptor('really tall')

class Test(HeightDescr, IPlant):
pass

self.assertEqual(frozenset([]), Test._pi.abstractproperties)


class TestPropertyImplementations(unittest.TestCase):
Expand Down

0 comments on commit 7c0215e

Please sign in to comment.