From ce579072ab6aeab30c52c5940384e2750a3dd288 Mon Sep 17 00:00:00 2001 From: David Montague <35119617+dmontagu@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:06:37 -0600 Subject: [PATCH] Clean up the check --- pydantic/mypy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydantic/mypy.py b/pydantic/mypy.py index 65b49c8a736..9eee976754f 100644 --- a/pydantic/mypy.py +++ b/pydantic/mypy.py @@ -348,7 +348,7 @@ def to_argument(self, current_info: TypeInfo, typed: bool, force_optional: bool, def expand_type(self, current_info: TypeInfo) -> Type | None: """Based on mypy.plugins.dataclasses.DataclassAttribute.expand_type.""" # The hasattr check in the next line is only necessary to prevent errors in old versions of mypy - if self.type is not None and hasattr(self.info, 'self_type') and self.info.self_type is not None: + if self.type is not None and getattr(self.info, 'self_type', None) is not None: # In general, it is not safe to call `expand_type()` during semantic analyzis, # however this plugin is called very late, so all types should be fully ready. # Also, it is tricky to avoid eager expansion of Self types here (e.g. because