Skip to content

Commit

Permalink
Make a change that improves compatibility with legacy mypy versions
Browse files Browse the repository at this point in the history
  • Loading branch information
dmontagu committed Oct 4, 2023
1 parent fe758e5 commit 88d5e72
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pydantic/mypy.py
Expand Up @@ -347,7 +347,8 @@ 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."""
if self.type is not None and self.info.self_type is not None:
# The hasattr check in the next line is only necessary to prevents 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:
# 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
Expand Down

0 comments on commit 88d5e72

Please sign in to comment.