# HG changeset patch # User Paul Boddie # Date 1481236394 -3600 # Node ID 19b30b3612e7eb72e1493a898c04c7b06a3a881a # Parent 4849542ef9da9f43070e7c2e503112292a1c9752 Ensure that deduced types for "self" include the class of the method involved. diff -r 4849542ef9da -r 19b30b3612e7 deducer.py --- a/deducer.py Thu Dec 08 23:30:24 2016 +0100 +++ b/deducer.py Thu Dec 08 23:33:14 2016 +0100 @@ -23,7 +23,7 @@ get_attrname_from_location, get_attrnames, \ get_invoked_attributes, get_name_path, init_item, \ sorted_output, CommonOutput -from encoders import encode_attrnames, encode_access_location, \ +from encoders import encode_access_location, \ encode_constrained, encode_location, encode_usage, \ get_kinds, test_label_for_kind, test_label_for_type from errors import DeduceError @@ -1315,6 +1315,17 @@ # Constrain "self" references. if name == "self": + + # Test for the class of the method in the deduced types. + + class_name = self.in_method(unit_path) + + if class_name and class_name not in class_types and class_name not in only_instance_types: + raise DeduceError("In %s, usage {%s} is not directly supported by class %s or its instances." % + (unit_path, encode_usage(usage), class_name)) + + # Constrain the types to the class's hierarchy. + t = self.constrain_self_reference(unit_path, class_types, only_instance_types) if t: class_types, only_instance_types, module_types, constrained = t