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

Method already_defined

mypy/semanal.py:7596–7619  ·  view source on GitHub ↗
(
        self, name: str, ctx: Context, original_ctx: SymbolTableNode | SymbolNode | None, noun: str
    )

Source from the content-addressed store, hash-verified

7594 return {n for n in names if not n.startswith("__")}
7595
7596 def already_defined(
7597 self, name: str, ctx: Context, original_ctx: SymbolTableNode | SymbolNode | None, noun: str
7598 ) -> None:
7599 if isinstance(original_ctx, SymbolTableNode):
7600 node: SymbolNode | None = original_ctx.node
7601 elif isinstance(original_ctx, SymbolNode):
7602 node = original_ctx
7603 else:
7604 node = None
7605
7606 if isinstance(original_ctx, SymbolTableNode) and isinstance(original_ctx.node, MypyFile):
7607 # Since this is an import, original_ctx.node points to the module definition.
7608 # Therefore, its line number is always 1, which is not useful for this
7609 # error message.
7610 extra_msg = " (by an import)"
7611 elif node and node.line != -1 and self.is_local_name(node.fullname):
7612 # TODO: Using previous symbol node may give wrong line. We should use
7613 # the line number where the binding was established instead.
7614 extra_msg = f" on line {node.line}"
7615 else:
7616 extra_msg = " (possibly by an import)"
7617 self.fail(
7618 f'{noun} "{unmangle(name)}" already defined{extra_msg}', ctx, code=codes.NO_REDEF
7619 )
7620
7621 def name_already_defined(
7622 self, name: str, ctx: Context, original_ctx: SymbolTableNode | SymbolNode | None = None

Callers 3

visit_type_alias_stmtMethod · 0.95
name_already_definedMethod · 0.95

Calls 4

is_local_nameMethod · 0.95
failMethod · 0.95
unmangleFunction · 0.90
isinstanceFunction · 0.85

Tested by

no test coverage detected