From bf0572d9c686adadca4b18b719f46b1ad4206ce5 Mon Sep 17 00:00:00 2001 From: Victorien <65306057+Viicos@users.noreply.github.com> Date: Mon, 6 May 2024 18:13:13 +0200 Subject: [PATCH] Fix crash in the visitor implementation (#10) It was assumed to always be inside a class, which isn't true in a lot of cases --- src/flake8_pydantic/visitor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/flake8_pydantic/visitor.py b/src/flake8_pydantic/visitor.py index 65bfe0f..b3e2107 100644 --- a/src/flake8_pydantic/visitor.py +++ b/src/flake8_pydantic/visitor.py @@ -28,7 +28,9 @@ def leave_class(self) -> None: self.class_stack.pop() @property - def current_class(self) -> ClassType: + def current_class(self) -> ClassType | None: + if not self.class_stack: + return None return self.class_stack[-1] def _check_pyd_001(self, node: ast.AnnAssign) -> None: