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

Method visit_index_expr

mypy/stubgen.py:343–357  ·  view source on GitHub ↗
(self, node: IndexExpr)

Source from the content-addressed store, hash-verified

341 return self._visit_literal_node(node)
342
343 def visit_index_expr(self, node: IndexExpr) -> str:
344 base_fullname = self.stubgen.get_fullname(node.base)
345 if base_fullname == "typing.Union":
346 if isinstance(node.index, TupleExpr):
347 return " | ".join([item.accept(self) for item in node.index.items])
348 return node.index.accept(self)
349 if base_fullname == "typing.Optional":
350 if isinstance(node.index, TupleExpr):
351 return self.stubgen.add_name("_typeshed.Incomplete")
352 return f"{node.index.accept(self)} | None"
353 base = node.base.accept(self)
354 index = node.index.accept(self)
355 if len(index) > 2 and index.startswith("(") and index.endswith(")"):
356 index = index[1:-1].rstrip(",")
357 return f"{base}[{index}]"
358
359 def visit_tuple_expr(self, node: TupleExpr) -> str:
360 suffix = "," if len(node.items) == 1 else ""

Callers

nothing calls this directly

Calls 9

isinstanceFunction · 0.85
lenFunction · 0.85
get_fullnameMethod · 0.80
add_nameMethod · 0.80
rstripMethod · 0.80
joinMethod · 0.45
acceptMethod · 0.45
startswithMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected