From 762a29b7050325300cc8fe7087e48307f7702014 Mon Sep 17 00:00:00 2001 From: James Westman Date: Sat, 30 Apr 2022 15:29:08 -0500 Subject: [PATCH] gir: Allow looking up basic types by name --- blueprintcompiler/gir.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/blueprintcompiler/gir.py b/blueprintcompiler/gir.py index 3786078..4e3279e 100644 --- a/blueprintcompiler/gir.py +++ b/blueprintcompiler/gir.py @@ -106,30 +106,41 @@ class BasicType(GirType): class BoolType(BasicType): name = "bool" + glib_type_name = "gboolean" + def assignable_to(self, other) -> bool: return isinstance(other, BoolType) class IntType(BasicType): name = "int" + glib_type_name = "gint" + def assignable_to(self, other) -> bool: return isinstance(other, IntType) or isinstance(other, UIntType) or isinstance(other, FloatType) class UIntType(BasicType): name = "uint" + glib_type_name = "guint" + def assignable_to(self, other) -> bool: return isinstance(other, IntType) or isinstance(other, UIntType) or isinstance(other, FloatType) class FloatType(BasicType): name = "float" + glib_type_name = "gfloat" + def assignable_to(self, other) -> bool: return isinstance(other, FloatType) class StringType(BasicType): name = "string" + glib_type_name = "gchararray" + def assignable_to(self, other) -> bool: return isinstance(other, StringType) _BASIC_TYPES = { + "bool": BoolType, "gboolean": BoolType, "int": IntType, "gint": IntType, @@ -623,6 +634,9 @@ class GirContext: def get_type(self, name: str, ns: str) -> T.Optional[GirNode]: + if ns is None and name in _BASIC_TYPES: + return _BASIC_TYPES[name]() + ns = ns or "Gtk" if ns not in self.namespaces: