From 3ab534312da0b3397d72ddb9883470690a54f7fa Mon Sep 17 00:00:00 2001 From: David Peter Date: Wed, 2 Apr 2025 10:53:11 +0200 Subject: [PATCH] `property.__get__`: overload to model class-access behavior Add a new overload for `property.__get__` to model the behavior that a property returns itself when accessed on a class object (when `instance` is set to `None`). The relevant section in the pseudo-implementation of `property` can be found at [1]. [1]: https://github.com/python/cpython/blob/87d9983994e9a423e9e0050b1bbee52ebaf84367/Objects/descrobject.c#L1541-L1542 --- stdlib/builtins.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index c9f6efafd6e9..9129c0cba20f 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -1281,6 +1281,9 @@ class property: def getter(self, fget: Callable[[Any], Any], /) -> property: ... def setter(self, fset: Callable[[Any, Any], None], /) -> property: ... def deleter(self, fdel: Callable[[Any], None], /) -> property: ... + @overload + def __get__(self, instance: None, owner: type, /) -> Self: ... + @overload def __get__(self, instance: Any, owner: type | None = None, /) -> Any: ... def __set__(self, instance: Any, value: Any, /) -> None: ... def __delete__(self, instance: Any, /) -> None: ...