def _property_to_types(self, node, v): """Convert a property to a list of PyTD types.""" if not v.fget: return [pytd.AnythingType()] getter_options = v.fget.FilteredData(v.vm.exitpoint) if not all(isinstance(o, abstract.Function) for o in getter_options): return [pytd.AnythingType()] types = [] for val in getter_options: if isinstance(val, abstract.InterpreterFunction): combinations = val.get_call_combinations(node) for node_after, _, return_value in combinations: types.append( self._function_call_to_return_type( node_after, val, return_value, len(combinations))) elif isinstance(val, abstract.PyTDFunction): types.extend(sig.pytd_sig.return_type for sig in val.signatures) else: types.append(pytd.AnythingType()) safe_types = [] # types without type parameters for t in types: collector = visitors.CollectTypeParameters() t.Visit(collector) t = t.Visit( visitors.ReplaceTypeParameters( {p: p.upper_value for p in collector.params})) safe_types.append(t) return safe_types
def VisitSignature(self, sig): new_template = [] substitutions = {k: k for k in self.type_params_stack[-1].keys()} for item in sig.template: new_template += self._ReplaceByOuterIfNecessary(item, substitutions) if sig.template == new_template: return sig # Nothing changed. else: return sig.Replace(template=tuple(new_template)).Visit( visitors.ReplaceTypeParameters(substitutions)).Visit(SimplifyUnions())