diff --git a/changes/2743-uriyyo.md b/changes/2743-uriyyo.md new file mode 100644 index 0000000..29d58aa --- /dev/null +++ b/changes/2743-uriyyo.md @@ -0,0 +1 @@ +Fix mypy plugin issue with self field declaration. \ No newline at end of file diff --git a/pydantic/mypy.py b/pydantic/mypy.py index 0598ef5..8107b54 100644 --- a/pydantic/mypy.py +++ b/pydantic/mypy.py @@ -619,7 +619,7 @@ def add_method( # first = [] else: self_type = self_type or fill_typevars(info) - first = [Argument(Var('self'), self_type, None, ARG_POS)] + first = [Argument(Var('__pydantic_self__'), self_type, None, ARG_POS)] args = first + args arg_types, arg_names, arg_kinds = [], [], [] for arg in args: diff --git a/tests/mypy/modules/plugin_success.py b/tests/mypy/modules/plugin_success.py index d24f8cb..1f334ee 100644 --- a/tests/mypy/modules/plugin_success.py +++ b/tests/mypy/modules/plugin_success.py @@ -158,3 +158,7 @@ class NotFrozenModel(FrozenModel): NotFrozenModel(x=1).x = 2 NotFrozenModel.from_orm(model) + + +class ModelWithSelfField(BaseModel): + self: str