This commit is contained in:
Selim Belhaouane
2020-10-08 16:07:22 -04:00
committed by GitHub
parent 55e78cc106
commit b99c37e3d0
3 changed files with 12 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
Fix false positive from mypy plugin when a class nested within a `BaseModel` is named `Model`.
+1 -1
View File
@@ -328,7 +328,7 @@ class PydanticModelTransformer:
construct_arguments = [fields_set_argument] + construct_arguments
obj_type = ctx.api.named_type('__builtins__.object')
self_tvar_name = 'Model'
self_tvar_name = '_PydanticBaseModel' # Make sure it does not conflict with other names in the class
tvar_fullname = ctx.cls.fullname + '.' + self_tvar_name
tvd = TypeVarDef(self_tvar_name, tvar_fullname, -1, [], obj_type)
self_tvar_expr = TypeVarExpr(self_tvar_name, tvar_fullname, [], obj_type)
+10
View File
@@ -123,3 +123,13 @@ p = AddProject(name='x', slug='y', description='z')
class TypeAliasAsAttribute(BaseModel):
__type_alias_attribute__ = Union[str, bytes]
class NestedModel(BaseModel):
class Model(BaseModel):
id: str
model: Model
_ = NestedModel.Model