From dcdd0e46ee618db251a62751d319f9e820bb9992 Mon Sep 17 00:00:00 2001 From: zedzhen <59135268+zedzhen@users.noreply.github.com> Date: Sun, 8 Nov 2026 12:43:23 +0300 Subject: [PATCH] The metaclass property takes precedence over class attributes. --- mypy/checkmember.py | 5 +++++ test-data/unit/check-classes.test | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/mypy/checkmember.py b/mypy/checkmember.py index e01d1e6a8579..fef70ddccd04 100644 --- a/mypy/checkmember.py +++ b/mypy/checkmember.py @@ -1150,6 +1150,11 @@ def analyze_class_attribute_access( of E in the expression E.var, original_vars are type variables of the class callable (for generic classes). """ + + mcs_func_info = mcs_fallback.type.get_method(name) + if isinstance(mcs_func_info, Decorator) and mcs_func_info.var.is_property: + return analyze_decorator_or_funcbase_access(mcs_func_info, mcs_fallback, name, mx) + info = itype.type if override_info: info = override_info diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index 48910c0e64ce..1fe4b8a6a668 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -9850,3 +9850,31 @@ fs = [lambda df, x: df.foo, f] reveal_type(fs) # N: Revealed type is "builtins.list[def (Any, Any) -> builtins.int | Any]" fs2 = [f, lambda df, x: df.foo] reveal_type(fs2) # N: Revealed type is "builtins.list[def (Any, Any) -> builtins.int | Any]" + +[case testMetaclassProperty] +class M(type): + @property + def f(cls) -> str: + return "1" + + @property + def g(cls) -> str: + return "1" + + def h(cls) -> str: + return "2" + +class A(metaclass=M): + @property + def f(self) -> str: + return type(self).f + + g: int = 1 + +reveal_type(A.f) # N: Revealed type is "builtins.str" +reveal_type(A().f) # N: Revealed type is "builtins.str" +reveal_type(A.g) # N: Revealed type is "builtins.str" +reveal_type(A().g) # N: Revealed type is "builtins.int" +reveal_type(A.h) # N: Revealed type is "def () -> builtins.str" + +[builtins fixtures/property.pyi]