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

Fix #1770 #1771

Merged
merged 1 commit into from
Oct 8, 2020
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/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