From 0d1ed534acd7bedbbbaae72772d1ff83b10aa7b9 Mon Sep 17 00:00:00 2001 From: Yurii Karabas <1998uriyyo@gmail.com> Date: Sat, 4 Sep 2021 05:15:49 +0300 Subject: [PATCH] Fix mypy plugin issue with self field (#2743) * Fix mypy issue with self field * Add docs --- changes/2743-uriyyo.md | 1 + pydantic/mypy.py | 2 +- tests/mypy/modules/plugin_success.py | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changes/2743-uriyyo.md 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