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

Add support for removing TypeVarDef in mypy 0.920 #3175

Merged
merged 5 commits into from Dec 18, 2021
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changes/3175-christianbundy.md
@@ -0,0 +1 @@
Add support for Mypy 0.920
17 changes: 15 additions & 2 deletions pydantic/mypy.py
Expand Up @@ -14,6 +14,14 @@

warnings.warn('No TOML parser installed, cannot read configuration from `pyproject.toml`.')
toml = None # type: ignore

try:
from mypy.types import TypeVarDef
except ImportError: # pragma: no cover
# Backward-compatible with TypeVarDef from Mypy 0.910.
from mypy.types import TypeVarType as TypeVarDef # type: ignore[misc]


from mypy.errorcodes import ErrorCode
from mypy.nodes import (
ARG_NAMED,
Expand Down Expand Up @@ -59,7 +67,6 @@
Type,
TypeOfAny,
TypeType,
TypeVarDef,
TypeVarType,
UnionType,
get_proper_type,
Expand Down Expand Up @@ -359,7 +366,13 @@ def add_construct_method(self, fields: List['PydanticModelField']) -> None:
tvd = TypeVarDef(self_tvar_name, tvar_fullname, -1, [], obj_type)
self_tvar_expr = TypeVarExpr(self_tvar_name, tvar_fullname, [], obj_type)
ctx.cls.info.names[self_tvar_name] = SymbolTableNode(MDEF, self_tvar_expr)
self_type = TypeVarType(tvd)

# Backward-compatible with TypeVarDef from Mypy 0.910.
if isinstance(tvd, TypeVarType): # pragma: no cover
self_type = tvd
else:
self_type = TypeVarType(tvd)

add_method(
ctx,
'construct',
Expand Down