1.1 --- a/deducer.py Thu Dec 08 23:30:24 2016 +0100
1.2 +++ b/deducer.py Thu Dec 08 23:33:14 2016 +0100
1.3 @@ -23,7 +23,7 @@
1.4 get_attrname_from_location, get_attrnames, \
1.5 get_invoked_attributes, get_name_path, init_item, \
1.6 sorted_output, CommonOutput
1.7 -from encoders import encode_attrnames, encode_access_location, \
1.8 +from encoders import encode_access_location, \
1.9 encode_constrained, encode_location, encode_usage, \
1.10 get_kinds, test_label_for_kind, test_label_for_type
1.11 from errors import DeduceError
1.12 @@ -1315,6 +1315,17 @@
1.13 # Constrain "self" references.
1.14
1.15 if name == "self":
1.16 +
1.17 + # Test for the class of the method in the deduced types.
1.18 +
1.19 + class_name = self.in_method(unit_path)
1.20 +
1.21 + if class_name and class_name not in class_types and class_name not in only_instance_types:
1.22 + raise DeduceError("In %s, usage {%s} is not directly supported by class %s or its instances." %
1.23 + (unit_path, encode_usage(usage), class_name))
1.24 +
1.25 + # Constrain the types to the class's hierarchy.
1.26 +
1.27 t = self.constrain_self_reference(unit_path, class_types, only_instance_types)
1.28 if t:
1.29 class_types, only_instance_types, module_types, constrained = t