Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compatibility with legacy mypy versions #7742

Merged
merged 2 commits into from Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 getattr in the next line is used to prevent errors in legacy versions of mypy without this attribute
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
Expand Down