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

Method translate_stmt_list

mypy/fastparse.py:454–527  ·  view source on GitHub ↗
(
        self,
        stmts: Sequence[ast3.stmt],
        *,
        ismodule: bool = False,
        can_strip: bool = False,
        is_coroutine: bool = False,
    )

Source from the content-addressed store, hash-verified

452 return node.lineno
453
454 def translate_stmt_list(
455 self,
456 stmts: Sequence[ast3.stmt],
457 *,
458 ismodule: bool = False,
459 can_strip: bool = False,
460 is_coroutine: bool = False,
461 ) -> list[Statement]:
462 # A "# type: ignore" comment before the first statement of a module
463 # ignores the whole module:
464 if (
465 ismodule
466 and stmts
467 and self.type_ignores
468 and (first := min(self.type_ignores)) < self.get_lineno(stmts[0])
469 ):
470 ignores = self.type_ignores.pop(first)
471 if ignores:
472 joined_ignores = ", ".join(ignores)
473 self.fail(
474 message_registry.TYPE_IGNORE_WITH_ERRCODE_ON_MODULE.format(joined_ignores),
475 line=first,
476 column=0,
477 blocker=False,
478 )
479 block = Block(self.fix_function_overloads(self.translate_stmt_list(stmts)))
480 self.set_block_lines(block, stmts)
481 mark_block_unreachable(block)
482 return [block]
483
484 stack = self.class_and_function_stack
485 # Fast case for stripping function bodies
486 if (
487 can_strip
488 and self.strip_function_bodies
489 and len(stack) == 1
490 and stack[0] == "F"
491 and not is_coroutine
492 ):
493 return []
494
495 res: list[Statement] = []
496 for stmt in stmts:
497 node = self.visit(stmt)
498 res.append(node)
499
500 # Slow case for stripping function bodies
501 if can_strip and self.strip_function_bodies:
502 if stack[-2:] == ["C", "F"]:
503 if is_possible_trivial_body(res):
504 can_strip = False
505 else:
506 # We only strip method bodies if they don't assign to an attribute, as
507 # this may define an attribute which has an externally visible effect.
508 visitor = FindAttributeAssign()
509 for s in res:
510 s.accept(visitor)
511 if visitor.found:

Callers 3

as_blockMethod · 0.95
as_required_blockMethod · 0.95
visit_ModuleMethod · 0.95

Calls 15

get_linenoMethod · 0.95
failMethod · 0.95
set_block_linesMethod · 0.95
visitMethod · 0.95
BlockClass · 0.90
mark_block_unreachableFunction · 0.90
minFunction · 0.85
lenFunction · 0.85
is_possible_trivial_bodyFunction · 0.85
FindAttributeAssignClass · 0.85
FindYieldClass · 0.85

Tested by

no test coverage detected