From 26c684081433efe9855e384266d33ead592c1cd4 Mon Sep 17 00:00:00 2001 From: correctmost <134317971+correctmost@users.noreply.github.com> Date: Tue, 6 Aug 2024 21:47:01 -0400 Subject: [PATCH] Avoid overhead of cast() calls when not type checking --- astroid/transforms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/astroid/transforms.py b/astroid/transforms.py index 5f0e533136..2ec576f897 100644 --- a/astroid/transforms.py +++ b/astroid/transforms.py @@ -78,7 +78,9 @@ def _transform(self, node: SuccessfulInferenceResult) -> SuccessfulInferenceResu def _visit(self, node: nodes.NodeNG) -> SuccessfulInferenceResult: for name in node._astroid_fields: value = getattr(node, name) - value = cast(_Vistables, value) + if TYPE_CHECKING: + value = cast(_Vistables, value) + visited = self._visit_generic(value) if visited != value: setattr(node, name, visited)