From 1e16b759271dd94e7052b0ec771fd1d93a1f7169 Mon Sep 17 00:00:00 2001 From: kramo Date: Mon, 10 Nov 2025 15:14:28 +0100 Subject: [PATCH] typing: GObject: Type Properties using inference This seems to work consistently, automatically unless you rely on the implicit nullability of a property. In that case, you will need to manually type it as: ``` prop = GObject.Property[T | None](type=T) ``` However, given that this behavior is ignored in other places and that the alternative would be wildly more annoying to deal with, it should probably be fine. --- src/gi-stubs/repository/GObject.pyi | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gi-stubs/repository/GObject.pyi b/src/gi-stubs/repository/GObject.pyi index b89a3dbe..e94abbe3 100644 --- a/src/gi-stubs/repository/GObject.pyi +++ b/src/gi-stubs/repository/GObject.pyi @@ -2338,13 +2338,13 @@ class PollFD(GBoxed): revents: int = ... # override -class Property: +class Property[T]: def __init__( self, getter: typing.Optional[typing.Callable[[typing.Any], typing.Any]] = None, setter: typing.Optional[typing.Callable[[typing.Any, typing.Any], None]] = None, - type: typing.Type[typing.Any] | None = None, - default: typing.Any = None, + type: typing.Type[T] | None = None, + default: T | None = None, nick: str = "", blurb: str = "", flags: int = PARAM_READWRITE, @@ -2352,8 +2352,8 @@ class Property: maximum: typing.Any = None, ) -> None: ... def __call__(self, fget: typing.Callable[[typing.Any], typing.Any]) -> Property: ... - def __get__(self, instance: Object, klass: typing.Any) -> typing.Any: ... - def __set__(self, instance: Object, value: typing.Any) -> None: ... + def __get__(self, instance: Object, klass: typing.Any) -> T: ... + def __set__(self, instance: Object, value: T) -> None: ... def get_pspec_args(self): ... def getter(self, fget: typing.Callable[[typing.Any], typing.Any]) -> Property: ... def setter(