Skip to content

Commit

Permalink
Fix #1770 (#1771)
Browse files Browse the repository at this point in the history
  • Loading branch information
selimb committed Oct 8, 2020
1 parent 55e78cc commit b99c37e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/1770-selimb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix false positive from mypy plugin when a class nested within a `BaseModel` is named `Model`.
2 changes: 1 addition & 1 deletion pydantic/mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def add_construct_method(self, fields: List['PydanticModelField']) -> None:
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)
Expand Down
10 changes: 10 additions & 0 deletions tests/mypy/modules/plugin_success.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,13 @@ class AddProject:

class TypeAliasAsAttribute(BaseModel):
__type_alias_attribute__ = Union[str, bytes]


class NestedModel(BaseModel):
class Model(BaseModel):
id: str

model: Model


_ = NestedModel.Model

0 comments on commit b99c37e

Please sign in to comment.