Skip to content

Commit

Permalink
Add support for removing TypeVarDef in mypy 0.920
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbundy committed Dec 16, 2021
1 parent d36bb74 commit 7ca3972
Showing 1 changed file with 15 additions and 2 deletions.
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:
# 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):
self_type = tvd
else:
self_type = TypeVarType(tvd)

add_method(
ctx,
'construct',
Expand Down

0 comments on commit 7ca3972

Please sign in to comment.