@dispatch
def visit(self, node: astx.SubscriptExpr) -> None:
"""
title: Visit SubscriptExpr nodes.
parameters:
node:
type: astx.SubscriptExpr
"""
self.visit(node.value)
if not isinstance(node.index, astx.LiteralNone):
self.visit(node.index)
value_type = self._expr_type(node.value)
if isinstance(node.value, astx.LiteralDict):
if not node.value.elements:
self.context.diagnostics.add(
"SubscriptExpr: key lookup on empty dict",
node=node,
)
elif not isinstance(
node.index,
(
astx.LiteralInt8,
astx.LiteralInt16,
astx.LiteralInt32,
astx.LiteralInt64,
astx.LiteralUInt8,
astx.LiteralUInt16,
astx.LiteralUInt32,
astx.LiteralUInt64,
astx.LiteralFloat32,
astx.LiteralFloat64,
astx.Identifier,
),
):
self.context.diagnostics.add(
"SubscriptExpr: only integer and floating-point "
"dict keys are supported",
node=node,
)
self._set_type(
node,
cast(
astx.DataType | None,
getattr(value_type, "value_type", None),
),
)