The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(lint): restrict freezing-wrapper match to bare names and types.MappingProxyType
mateo-berri089a4fa228db
diff --git a/scripts/check_type_discipline.py b/scripts/check_type_discipline.pyindex 88679f28190..43a4cb66484 100644--- a/scripts/check_type_discipline.py+++ b/scripts/check_type_discipline.py@@ -386,12 +386,15 @@ def _annotation_node_ids(tree: ast.AST) -> frozenset[int]:)-def _callable_name(func: ast.expr) -> str | None:+def _is_freezing_wrapper(func: ast.expr) -> bool:if isinstance(func, ast.Name):- return func.id- if isinstance(func, ast.Attribute):- return func.attr- return None+ return func.id in FREEZING_WRAPPERS+ return (+ isinstance(func, ast.Attribute)+ and func.attr == "MappingProxyType"+ and isinstance(func.value, ast.Name)+ and func.value.id == "types"+ )def _frozen_argument_ids(tree: ast.AST) -> frozenset[int]:@@ -400,14 +403,14 @@ def _frozen_argument_ids(tree: ast.AST) -> frozenset[int]:`MappingProxyType({...})`, `frozenset({...})`, and `tuple([...])` freeze theirargument before it can escape, so the literal inside is a one-shot build, not amutable value anyone can grow later. Only the argument itself is exempt; a- mutable collection nested inside it still trips LIT002.+ mutable collection nested inside it still trips LIT002. Only bare names (plus+ `types.MappingProxyType`) qualify, so an unrelated method that happens to share+ a wrapper's name cannot exempt its argument."""return frozenset(id(node.args[0])for node in ast.walk(tree)- if isinstance(node, ast.Call)- and len(node.args) == 1- and _callable_name(node.func) in FREEZING_WRAPPERS+ if isinstance(node, ast.Call) and len(node.args) == 1 and _is_freezing_wrapper(node.func))diff --git a/tests/test_litellm/test_check_type_discipline.py b/tests/test_litellm/test_check_type_discipline.pyindex f624eb926d1..53d672fc4a8 100644--- a/tests/test_litellm/test_check_type_discipline.py+++ b/tests/test_litellm/test_check_type_discipline.py@@ -160,6 +160,12 @@ def test_value_frozen_by_wrapper_is_exempt(tmp_path):assert "LIT002" not in _codes(tmp_path, "t = tuple([1, 2])\n")+def test_same_named_method_does_not_exempt_its_argument(tmp_path):+ assert "LIT002" in _codes(tmp_path, "t = obj.tuple([1, 2])\n")+ assert "LIT002" in _codes(tmp_path, "f = obj.frozenset({1, 2})\n")+ assert "LIT002" in _codes(tmp_path, "m = obj.MappingProxyType({'a': 1})\n")++def test_mutable_nested_inside_frozen_wrapper_still_counts(tmp_path):assert "LIT002" in _codes(tmp_path, "from types import MappingProxyType\nm = MappingProxyType({'a': []})\n")