:right-sidebar: True VariantType =================================================================== .. currentmodule:: gi.repository.GLib .. versionadded:: 2.24 .. class:: VariantType(**kwargs) :no-contents-entry: :Constructors: :: new(type_string:str) -> GLib.VariantType new_array(element:GLib.VariantType) -> GLib.VariantType new_dict_entry(key:GLib.VariantType, value:GLib.VariantType) -> GLib.VariantType new_maybe(element:GLib.VariantType) -> GLib.VariantType new_tuple(items:list) -> GLib.VariantType Constructors ------------ .. rst-class:: interim-class .. class:: VariantType :no-index: .. classmethod:: new(type_string: str) -> ~gi.repository.GLib.VariantType Creates a new :obj:`~gi.repository.GLib.VariantType` corresponding to the type string given by ``type_string``. It is appropriate to call :func:`~gi.repository.GLib.VariantType.free` on the return value. It is a programmer error to call this function with an invalid type string. Use :func:`~gi.repository.GLib.VariantType.string_is_valid` if you are unsure. .. versionadded:: 2.24 :param type_string: a valid GVariant type string .. classmethod:: new_array(element: ~gi.repository.GLib.VariantType) -> ~gi.repository.GLib.VariantType Constructs the type corresponding to an array of elements of the type ``type``. It is appropriate to call :func:`~gi.repository.GLib.VariantType.free` on the return value. :param element: a :obj:`~gi.repository.GLib.VariantType` .. classmethod:: new_dict_entry(key: ~gi.repository.GLib.VariantType, value: ~gi.repository.GLib.VariantType) -> ~gi.repository.GLib.VariantType Constructs the type corresponding to a dictionary entry with a key of type ``key`` and a value of type ``value``. It is appropriate to call :func:`~gi.repository.GLib.VariantType.free` on the return value. :param key: a basic :obj:`~gi.repository.GLib.VariantType` :param value: a :obj:`~gi.repository.GLib.VariantType` .. classmethod:: new_maybe(element: ~gi.repository.GLib.VariantType) -> ~gi.repository.GLib.VariantType Constructs the type corresponding to a maybe instance containing type ``type`` or Nothing. It is appropriate to call :func:`~gi.repository.GLib.VariantType.free` on the return value. :param element: a :obj:`~gi.repository.GLib.VariantType` .. classmethod:: new_tuple(items: ~typing.Sequence[~gi.repository.GLib.VariantType]) -> ~gi.repository.GLib.VariantType Constructs a new tuple type, from ``items``. ``length`` is the number of items in ``items``, or -1 to indicate that ``items`` is :const:`None`-terminated. It is appropriate to call :func:`~gi.repository.GLib.VariantType.free` on the return value. :param items: an array of :obj:`~gi.repository.GLib.VariantType`, one for each item Methods ------- .. rst-class:: interim-class .. class:: VariantType :no-index: .. method:: checked_(type_string: str) -> ~gi.repository.GLib.VariantType :param type_string: .. method:: dup_string() -> str Returns a newly-allocated copy of the type string corresponding to ``type``. The returned string is nul-terminated. It is appropriate to call :func:`~gi.repository.GLib.free` on the return value. .. method:: element() -> ~gi.repository.GLib.VariantType Determines the element type of an array or maybe type. This function may only be used with array or maybe types. .. method:: equal(type2: ~gi.repository.GLib.VariantType) -> bool Compares ``type1`` and ``type2`` for equality. Only returns :const:`True` if the types are exactly equal. Even if one type is an indefinite type and the other is a subtype of it, :const:`False` will be returned if they are not exactly equal. If you want to check for subtypes, use :func:`~gi.repository.GLib.VariantType.is_subtype_of`. The argument types of ``type1`` and ``type2`` are only :obj:`~gi.repository.gpointer` to allow use with :obj:`~gi.repository.GLib.HashTable` without function pointer casting. For both arguments, a valid :obj:`~gi.repository.GLib.VariantType` must be provided. :param type2: a :obj:`~gi.repository.GLib.VariantType` .. method:: first() -> ~gi.repository.GLib.VariantType Determines the first item type of a tuple or dictionary entry type. This function may only be used with tuple or dictionary entry types, but must not be used with the generic tuple type ``%G_VARIANT_TYPE_TUPLE``. In the case of a dictionary entry type, this returns the type of the key. :const:`None` is returned in case of ``type`` being ``%G_VARIANT_TYPE_UNIT``. This call, together with :func:`~gi.repository.GLib.VariantType.next` provides an iterator interface over tuple and dictionary entry types. .. method:: free() -> None Frees a :obj:`~gi.repository.GLib.VariantType` that was allocated with :func:`~gi.repository.GLib.VariantType.copy`, :func:`~gi.repository.GLib.VariantType.new` or one of the container type constructor functions. In the case that ``type`` is :const:`None`, this function does nothing. Since 2.24 .. method:: get_string_length() -> int Returns the length of the type string corresponding to the given ``type``. This function must be used to determine the valid extent of the memory region returned by :func:`~gi.repository.GLib.VariantType.peek_string`. .. method:: hash() -> int Hashes ``type``. The argument type of ``type`` is only :obj:`~gi.repository.gpointer` to allow use with :obj:`~gi.repository.GLib.HashTable` without function pointer casting. A valid :obj:`~gi.repository.GLib.VariantType` must be provided. .. method:: is_array() -> bool Determines if the given ``type`` is an array type. This is true if the type string for ``type`` starts with an 'a'. This function returns :const:`True` for any indefinite type for which every definite subtype is an array type -- ``%G_VARIANT_TYPE_ARRAY``, for example. .. method:: is_basic() -> bool Determines if the given ``type`` is a basic type. Basic types are booleans, bytes, integers, doubles, strings, object paths and signatures. Only a basic type may be used as the key of a dictionary entry. This function returns :const:`False` for all indefinite types except ``%G_VARIANT_TYPE_BASIC``. .. method:: is_container() -> bool Determines if the given ``type`` is a container type. Container types are any array, maybe, tuple, or dictionary entry types plus the variant type. This function returns :const:`True` for any indefinite type for which every definite subtype is a container -- ``%G_VARIANT_TYPE_ARRAY``, for example. .. method:: is_definite() -> bool Determines if the given ``type`` is definite (ie: not indefinite). A type is definite if its type string does not contain any indefinite type characters ('*', '?', or 'r'). A :obj:`~gi.repository.GLib.Variant` instance may not have an indefinite type, so calling this function on the result of :func:`~gi.repository.GLib.Variant.get_type` will always result in :const:`True` being returned. Calling this function on an indefinite type like ``%G_VARIANT_TYPE_ARRAY``, however, will result in :const:`False` being returned. .. method:: is_dict_entry() -> bool Determines if the given ``type`` is a dictionary entry type. This is true if the type string for ``type`` starts with a '{'. This function returns :const:`True` for any indefinite type for which every definite subtype is a dictionary entry type -- ``%G_VARIANT_TYPE_DICT_ENTRY``, for example. .. method:: is_maybe() -> bool Determines if the given ``type`` is a maybe type. This is true if the type string for ``type`` starts with an 'm'. This function returns :const:`True` for any indefinite type for which every definite subtype is a maybe type -- ``%G_VARIANT_TYPE_MAYBE``, for example. .. method:: is_subtype_of(supertype: ~gi.repository.GLib.VariantType) -> bool Checks if ``type`` is a subtype of ``supertype``. This function returns :const:`True` if ``type`` is a subtype of ``supertype``. All types are considered to be subtypes of themselves. Aside from that, only indefinite types can have subtypes. :param supertype: a :obj:`~gi.repository.GLib.VariantType` .. method:: is_tuple() -> bool Determines if the given ``type`` is a tuple type. This is true if the type string for ``type`` starts with a '(' or if ``type`` is ``%G_VARIANT_TYPE_TUPLE``. This function returns :const:`True` for any indefinite type for which every definite subtype is a tuple type -- ``%G_VARIANT_TYPE_TUPLE``, for example. .. method:: is_variant() -> bool Determines if the given ``type`` is the variant type. .. method:: key() -> ~gi.repository.GLib.VariantType Determines the key type of a dictionary entry type. This function may only be used with a dictionary entry type. Other than the additional restriction, this call is equivalent to :func:`~gi.repository.GLib.VariantType.first`. .. method:: n_items() -> int Determines the number of items contained in a tuple or dictionary entry type. This function may only be used with tuple or dictionary entry types, but must not be used with the generic tuple type ``%G_VARIANT_TYPE_TUPLE``. In the case of a dictionary entry type, this function will always return 2. .. method:: next() -> ~gi.repository.GLib.VariantType Determines the next item type of a tuple or dictionary entry type. ``type`` must be the result of a previous call to :func:`~gi.repository.GLib.VariantType.first` or :func:`~gi.repository.GLib.VariantType.next`. If called on the key type of a dictionary entry then this call returns the value type. If called on the value type of a dictionary entry then this call returns :const:`None`. For tuples, :const:`None` is returned when ``type`` is the last item in a tuple. .. method:: string_get_depth_(type_string: str) -> int :param type_string: .. method:: string_is_valid(type_string: str) -> bool Checks if ``type_string`` is a valid GVariant type string. This call is equivalent to calling :func:`~gi.repository.GLib.VariantType.string_scan` and confirming that the following character is a nul terminator. :param type_string: a pointer to any string .. method:: string_scan(string: str, limit: str | None = None) -> tuple[bool, str] Scan for a single complete and valid GVariant type string in ``string``. The memory pointed to by ``limit`` (or bytes beyond it) is never accessed. If a valid type string is found, ``endptr`` is updated to point to the first character past the end of the string that was found and :const:`True` is returned. If there is no valid type string starting at ``string``, or if the type string does not end before ``limit`` then :const:`False` is returned. For the simple case of checking if a string is a valid type string, see :func:`~gi.repository.GLib.VariantType.string_is_valid`. .. versionadded:: 2.24 :param string: a pointer to any string :param limit: the end of ``string``, or :const:`None` .. method:: value() -> ~gi.repository.GLib.VariantType Determines the value type of a dictionary entry type. This function may only be used with a dictionary entry type.