Typing Base Classes

class Any

Type that can be matched to any other type.

class EnumerableGenericMeta

Bases: pygears.typing.base.GenericMeta

Base class for all types that are iterable.

items()

Generator that yields (key, element) pairs.

keys()

Returns a list of keys that can be used for indexing the type.

class GenericMeta

Bases: pygears.typing.base.TypingMeta

Base class for all types that have a generic parameter.

args

Returns a list of values supplied for each generic parameter.

>>> Tuple[Uint[1], Uint[2]].args
[Uint[1], Uint[2]]
base

Returns base generic class of the type.

>>> assert Uint[16].base == Uint
fields

Returns the names of the generic parameters.

>>> Tuple[Uint[1], Uint[2]].fields
('f0', 'f1')
>>> Tuple[{'u1': Uint[1], 'u2': Uint[2]}].fields
('u0', 'u1')
is_generic()

Return True if no values have been supplied for the generic parameters.

>>> Uint.is_generic()
True
>>> Uint['template'].is_generic()
False
is_specified

Return True if all generic parameters were supplied concrete values.

>>> Uint['template'].is_specified()
False
>>> Uint[16].is_specified()
True
templates

Returns a list of templated generic variables within the type. The type is searched recursively. Each template is reported only once.

>>> Tuple[Tuple['T1', 'T2'], 'T1'].templates
['T1', 'T2']
exception TemplateArgumentsError

Bases: Exception

exception TemplatedTypeUnspecified

Bases: Exception

class TypingMeta

Bases: type

Base class all types.

typeof(obj, t)

Check if a specific type instance is a subclass of the type.

Parameters
  • obj – Concrete type instance

  • t – Base type class