types
Larky module containing functions checking types.
This module defines utility functions to assist in dynamic creation of new types. It also defines names for some object types that are used by the standard Python interpreter, but not exposed as builtins like int or str are. Finally, it provides some additional type-related utility classes and functions that are not fundamental enough to be builtins.
Similar to types.
types.MethodType(func, instance)
Binds func to the instance class.
types.is_bool(v)
Returns True if v is an instance of a bool.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a bool, False otherwise.
types.is_bytearray(v)
Returns True if v is an instance of a byte array.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a byte array, False otherwise.
types.is_bytelike(v)
Returns True if v is an instance of bytelike: bytes or byte array.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a bytelike, False otherwise.
types.is_bytes(v)
Returns True if v is an instance of a bytes.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a bytes, False otherwise.
types.is_callable(v)
Returns True if v is an instance of a callable: function or a lambda.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a callable, False otherwise.
types.is_dict(v)
Returns True if v is an instance of a dict.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a dict, False otherwise.
types.is_float(v)
Returns True if v is an instance of a floating point number.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a floating point number, False otherwise.
types.is_function(v)
Returns True if v is an instance of a function.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a function, False otherwise.
types.is_int(v)
Returns True if v is an instance of a signed integer.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a signed integer, False otherwise.
types.is_iterable(v)
Returns True if v is an instance of a range: tuple, list or range.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a iterable, False otherwise.
types.is_lambda(v)
Returns True if v is an instance of a lambda.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a lambda, False otherwise.
types.is_list(v)
Returns True if v is an instance of a list.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a list, False otherwise.
types.is_mutablestruct(v)
Returns True if v is a mutablestruct created by larky.mutablestruct().
Parameters:
v – the value whose type should be checked.
Returns: True if v was created by larky.mutablestruct(), False otherwise.
types.is_none(v)
Returns True if v is an instance of a None.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a None, False otherwise.
types.is_range(v)
Returns True if v is an instance of a range.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a range, False otherwise.
types.is_set(v)
Returns True if v is a set created by sets.make().
Parameters:
v – the value whose type should be checked.
Returns: True if v was created by sets.make(), False otherwise.
types.is_string(v)
Returns True if v is an instance of a string.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a string, False otherwise.
types.is_structlike(v)
Returns True if v is an instance of structlike.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a structlike, False otherwise.
types.is_subclass(sub_class, parent_class)
Returns True if v is a set created by sets.make().
Parameters:
sub_class – the value of class to chech.
parent_class – the value of a parent class to check inheritance with.
Returns: True if sub_class is inherited from parent_class, False otherwise.
types.is_tuple(v)
Returns True if v is an instance of a tuple.
Parameters:
v – the value whose type should be checked.
Returns: True if v is an instance of a tuple, False otherwise.
types.new_class(name, bases=(), kwds=None, exec_body=None)
Create a class object dynamically using the appropriate metaclass.
class MyStaticClass(object, metaclass=MySimpleMeta):
pass
is equivalent to:
MyStaticClass = types.new_class(
"MyStaticClass",
(object,),
{"metaclass": MyMeta},
lambda ns: ns
)
types.prepare_class(name, bases=(), kwds=None)
Calculates the appropriate metaclass and creates the class namespace. The arguments are the components that make up a class definition header: the class name, the base classes (in order) and the keyword arguments (such as metaclass).
Parameters:
name – is the appropriate metaclass.
metaclass – is the appropriate metaclass, namespace is the prepared class namespace and kwds is an updated copy of the passed in.
kwds argument with any ‘metaclass’ entry removed. If no kwds argument is passed in, this will be an empty dict. :param *kwds: is an updated copy of the passed in kwds argument with any.
Returns: (metaclass, namespace, kwds) as a 3-tuple.
types.resolve_bases(bases)
Resolve MRO entries dynamically as specified by PEP 560.
Last updated