MCPcopy Index your code
hub / github.com/python/mypy / flatten_rvalues

Method flatten_rvalues

mypy/checker.py:4028–4057  ·  view source on GitHub ↗

Flatten expression list by expanding those * items that have tuple type. For each regular type item in the tuple type use a TempNode(), for an Unpack item use a corresponding StarExpr(TempNode()).

(self, rvalues: list[Expression])

Source from the content-addressed store, hash-verified

4026 return False
4027
4028 def flatten_rvalues(self, rvalues: list[Expression]) -> list[Expression]:
4029 """Flatten expression list by expanding those * items that have tuple type.
4030
4031 For each regular type item in the tuple type use a TempNode(), for an Unpack
4032 item use a corresponding StarExpr(TempNode()).
4033 """
4034 new_rvalues = []
4035 for rv in rvalues:
4036 if not isinstance(rv, StarExpr):
4037 new_rvalues.append(rv)
4038 continue
4039 typ = get_proper_type(self.expr_checker.accept(rv.expr))
4040 if not isinstance(typ, TupleType):
4041 new_rvalues.append(rv)
4042 continue
4043 for t in typ.items:
4044 if not isinstance(t, UnpackType):
4045 new_rvalues.append(TempNode(t))
4046 else:
4047 unpacked = get_proper_type(t.type)
4048 if isinstance(unpacked, TypeVarTupleType):
4049 fallback = unpacked.upper_bound
4050 else:
4051 assert (
4052 isinstance(unpacked, Instance)
4053 and unpacked.type.fullname == "builtins.tuple"
4054 )
4055 fallback = unpacked
4056 new_rvalues.append(StarExpr(TempNode(fallback)))
4057 return new_rvalues
4058
4059 def check_assignment_to_multiple_lvalues(
4060 self,

Calls 6

get_proper_typeFunction · 0.90
TempNodeClass · 0.90
StarExprClass · 0.90
isinstanceFunction · 0.85
appendMethod · 0.80
acceptMethod · 0.45

Tested by

no test coverage detected