1.1 --- a/deducer.py Sun Mar 12 18:03:25 2017 +0100
1.2 +++ b/deducer.py Sun Mar 12 18:04:08 2017 +0100
1.3 @@ -1775,8 +1775,13 @@
1.4
1.5 "Convert 'ref' to a provider appropriate to its invocation result."
1.6
1.7 - if ref and ref.has_kind("<class>"):
1.8 - return ref
1.9 + if ref:
1.10 + if ref.has_kind("<class>"):
1.11 + return ref
1.12 + elif ref.has_kind("<function>"):
1.13 + refs = self.importer.all_return_values.get(ref.get_origin())
1.14 + if refs and len(refs) == 1:
1.15 + return first(refs)
1.16
1.17 return Reference("<var>")
1.18
1.19 @@ -1793,8 +1798,13 @@
1.20
1.21 "Convert 'ref' to its invocation result."
1.22
1.23 - if ref and ref.has_kind("<class>"):
1.24 - return ref.instance_of()
1.25 + if ref:
1.26 + if ref.has_kind("<class>"):
1.27 + return ref.instance_of()
1.28 + elif ref.has_kind("<function>"):
1.29 + refs = self.importer.all_return_values.get(ref.get_origin())
1.30 + if refs and len(refs) == 1:
1.31 + return first(refs)
1.32
1.33 return Reference("<var>")
1.34
2.1 --- a/importer.py Sun Mar 12 18:03:25 2017 +0100
2.2 +++ b/importer.py Sun Mar 12 18:04:08 2017 +0100
2.3 @@ -116,6 +116,10 @@
2.4 self.all_constants = {}
2.5 self.all_constant_values = {}
2.6
2.7 + # Return values.
2.8 +
2.9 + self.all_return_values = {}
2.10 +
2.11 self.make_cache()
2.12
2.13 def give_warning(self, name):
3.1 --- a/modules.py Sun Mar 12 18:03:25 2017 +0100
3.2 +++ b/modules.py Sun Mar 12 18:04:08 2017 +0100
3.3 @@ -115,6 +115,7 @@
3.4 self.propagate_name_references()
3.5 self.propagate_attr_accesses()
3.6 self.propagate_constants()
3.7 + self.propagate_return_values()
3.8
3.9 def unpropagate(self):
3.10
3.11 @@ -151,6 +152,7 @@
3.12 remove_items(self.importer.all_attr_access_modifiers, self.attr_access_modifiers)
3.13 remove_items(self.importer.all_constants, self.constants)
3.14 remove_items(self.importer.all_constant_values, self.constant_values)
3.15 + remove_items(self.importer.all_return_values, self.return_values)
3.16
3.17 # Remove this module's objects from the importer. Objects are
3.18 # automatically propagated when defined.
3.19 @@ -220,6 +222,12 @@
3.20 self.importer.all_instance_attrs[name] = self.instance_attrs.get(name) or {}
3.21 self.importer.all_instance_attr_constants[name] = self.instance_attr_constants.get(name) or {}
3.22
3.23 + def propagate_return_values(self):
3.24 +
3.25 + "Propagate return values for the module."
3.26 +
3.27 + self.importer.all_return_values.update(self.return_values)
3.28 +
3.29 def set_object(self, name, value=None):
3.30
3.31 "Set an object with the given 'name' and the given 'value'."