summaryrefslogtreecommitdiff
path: root/gi/_propertyhelper.py
diff options
context:
space:
mode:
Diffstat (limited to 'gi/_propertyhelper.py')
-rw-r--r--gi/_propertyhelper.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/gi/_propertyhelper.py b/gi/_propertyhelper.py
index def34b22..69357553 100644
--- a/gi/_propertyhelper.py
+++ b/gi/_propertyhelper.py
@@ -26,6 +26,21 @@ from ._constants import \
TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, \
TYPE_PYOBJECT, TYPE_GTYPE, TYPE_STRV, TYPE_VARIANT
+
+from typing import Optional
+try:
+ # Only available in Python 3.8 or later.
+ from typing import get_origin
+except ImportError:
+ from typing import _GenericAlias
+
+ def get_origin(type_: object) -> Optional[type]:
+ """Get the unsubscripted version of a type."""
+ if isinstance(type_, _GenericAlias):
+ return type_.__origin__
+ return None
+
+
G_MAXFLOAT = _gi.G_MAXFLOAT
G_MAXDOUBLE = _gi.G_MAXDOUBLE
G_MININT = _gi.G_MININT
@@ -249,12 +264,18 @@ class Property(object):
def _type_from_python(self, type_):
if type_ in self._type_from_pytype_lookup:
return self._type_from_pytype_lookup[type_]
- elif (isinstance(type_, type) and
- issubclass(type_, (_gi.GObject,
- _gi.GEnum,
- _gi.GFlags,
- _gi.GBoxed,
- _gi.GInterface))):
+
+ # Support instances of generic types such as Gio.ListStore[Gio.File]
+ origin = get_origin(type_)
+ if origin is not None:
+ type_ = origin
+
+ if (isinstance(type_, type) and
+ issubclass(type_, (_gi.GObject,
+ _gi.GEnum,
+ _gi.GFlags,
+ _gi.GBoxed,
+ _gi.GInterface))):
return type_.__gtype__
elif type_ in (TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR,
TYPE_INT, TYPE_UINT, TYPE_BOOLEAN, TYPE_LONG,