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

Method analyze_lvalue

mypy/semanal.py:4378–4426  ·  view source on GitHub ↗

Analyze an lvalue or assignment target. Args: lval: The target lvalue nested: If true, the lvalue is within a tuple or list lvalue expression explicit_type: Assignment has type annotation escape_comprehensions: If we are inside a comprehension

(
        self,
        lval: Lvalue,
        nested: bool = False,
        explicit_type: bool = False,
        is_final: bool = False,
        escape_comprehensions: bool = False,
        has_explicit_value: bool = False,
        is_index_var: bool = False,
    )

Source from the content-addressed store, hash-verified

4376 self.fail(msg, ctx)
4377
4378 def analyze_lvalue(
4379 self,
4380 lval: Lvalue,
4381 nested: bool = False,
4382 explicit_type: bool = False,
4383 is_final: bool = False,
4384 escape_comprehensions: bool = False,
4385 has_explicit_value: bool = False,
4386 is_index_var: bool = False,
4387 ) -> None:
4388 """Analyze an lvalue or assignment target.
4389
4390 Args:
4391 lval: The target lvalue
4392 nested: If true, the lvalue is within a tuple or list lvalue expression
4393 explicit_type: Assignment has type annotation
4394 escape_comprehensions: If we are inside a comprehension, set the variable
4395 in the enclosing scope instead. This implements
4396 https://www.python.org/dev/peps/pep-0572/#scope-of-the-target
4397 is_index_var: If lval is the index variable in a for loop
4398 """
4399 if escape_comprehensions:
4400 assert isinstance(lval, NameExpr), "assignment expression target must be NameExpr"
4401 if isinstance(lval, NameExpr):
4402 self.analyze_name_lvalue(
4403 lval,
4404 explicit_type,
4405 is_final,
4406 escape_comprehensions,
4407 has_explicit_value=has_explicit_value,
4408 is_index_var=is_index_var,
4409 )
4410 elif isinstance(lval, MemberExpr):
4411 self.analyze_member_lvalue(lval, explicit_type, is_final, has_explicit_value)
4412 if explicit_type and not self.is_self_member_ref(lval):
4413 self.fail("Type cannot be declared in assignment to non-self attribute", lval)
4414 elif isinstance(lval, IndexExpr):
4415 if explicit_type:
4416 self.fail("Unexpected type declaration", lval)
4417 lval.accept(self)
4418 elif isinstance(lval, TupleExpr):
4419 self.analyze_tuple_or_list_lvalue(lval, explicit_type)
4420 elif isinstance(lval, StarExpr):
4421 if nested:
4422 self.analyze_lvalue(lval.expr, nested, explicit_type)
4423 else:
4424 self.fail("Starred assignment target must be in a list or tuple", lval)
4425 else:
4426 self.fail("Invalid assignment target", lval)
4427
4428 def analyze_name_lvalue(
4429 self,

Callers 10

visit_assignment_exprMethod · 0.95
analyze_lvaluesMethod · 0.95
visit_for_stmtMethod · 0.95
analyze_try_stmtMethod · 0.95
visit_with_stmtMethod · 0.95
analyze_comp_forMethod · 0.95
visit_as_patternMethod · 0.95
visit_starred_patternMethod · 0.95
visit_mapping_patternMethod · 0.95

Calls 7

analyze_name_lvalueMethod · 0.95
analyze_member_lvalueMethod · 0.95
is_self_member_refMethod · 0.95
failMethod · 0.95
isinstanceFunction · 0.85
acceptMethod · 0.45

Tested by

no test coverage detected