adorn.unit.python module
Representation of python’s std lib
- class adorn.unit.python.Bool
Bases:
adorn.unit.python.BuiltInRepresentation of python’s
booltype- base_type
alias of
bool
- class adorn.unit.python.BuiltIn
Bases:
adorn.unit.python.PythonRepresentation of python’s built-in types
- classmethod additional_checks(orchestrator, obj)
Type checks specific to a given type
- Parameters
orchestrator (Orchestrator) – container of all types, typically unused
obj (Any) – an instance that will have additional type checking performed against it
- Returns
- either a
TypeCheckErrorcontaining the reason why the
objdidn’t pass the additional checks, otherwiseNone
- either a
- Return type
Optional[TypeCheckError]
- base_type: type
the built-in python type the subclass is supposed to represent
- hashable: bool = True
python’s built-in types are hashable
- unacceptable_subtype: Set[type] = {}
types that do not map to the given python built-in type. This exists to prevent
boolfrom being confused as anint.
- class adorn.unit.python.Float
Bases:
adorn.unit.python.BuiltInRepresentation of python’s
floattype- base_type
alias of
float
- class adorn.unit.python.Int
Bases:
adorn.unit.python.BuiltInRepresentation of python’s
inttype- classmethod additional_checks(orchestrator, obj)
Type checks specific to
int- Exceptions:
WrongTypeError:objwas of typebool, notint
- Parameters
orchestrator (Orchestrator) – container of all types, unused
obj (Any) – an instance that will have additional type checking performed against it
- Returns
- either a
TypeCheckErrorcontaining the reason why the
objdidn’t pass the additional checks, otherwiseNone
- either a
- Return type
Optional[TypeCheckError]
- base_type
alias of
int
- unacceptable_subtype: Set[type] = {<class 'bool'>}
types that do not map to the given python built-in type. This exists to prevent
boolfrom being confused as anint.
- class adorn.unit.python.Python
Bases:
adorn.unit.simple.SimpleUnitthat holds types in python’s std lib.- contains(obj, orchestrator)
Check if the type is part of python’s std lib.
- Parameters
obj (Any) – the type that may be part of python’s std lib
orchestrator (Orchestrator) – container of all types, typically used to recurse nested types
- Returns
if
True, the type is part of python’s std lib- Return type
bool
- get(key, orchestrator)
Return the relevant python std lib type
- Parameters
key (Any) – the type that may be part of python’s std lib
orchestrator (Orchestrator) – container of all types, typically used to recurse nested types
- Returns
- if
keyis part of python’s std lib, then the type that is meant to represent the python std lib type will be returned, otherwise
None
- if
- Return type
Optional[type]
- class adorn.unit.python.Ret
Bases:
adorn.unit.python.WrapperRepresents Python’s
Settype
- class adorn.unit.python.Rict
Bases:
adorn.unit.python.WrapperRepresents Python’s
Dicttype
- class adorn.unit.python.Rnion
Bases:
adorn.unit.python.WrapperRepresents Python’s
Uniontype
- class adorn.unit.python.Rterable
Bases:
adorn.unit.python.WrapperRepresentation of python’s
Iterabletype
- class adorn.unit.python.Ruple
Bases:
adorn.unit.python.WrapperRepresents Python’s
TupletypeNote
This representation of
Tupledoes not handle tuples of arbitrary length. The full length of theTuplemust be specified in the type signature at instantiation time.
- class adorn.unit.python.Str
Bases:
adorn.unit.python.BuiltInRepresentation of python’s
strtype- base_type
alias of
str
- class adorn.unit.python.Wrapper
Bases:
adorn.unit.python.PythonBase class for python wrapper types.
- static is_hashable(target_cls, target_arg, orchestrator, obj)
Check if a given type may be hashed.
- Exceptions:
UnRepresentedTypeError:the nested argument, did not map to any of the types contained in the
Orchestrator
HashableError:the nested argument, could not be hashed
- Parameters
target_cls (Type) – fully instantiated wrapper type
target_arg (Type) – nested type, that is required to be hashable
orchestrator (Orchestrator) – container of all types, used to recurse
obj (Iterable[Any]) – the instance, pre conversion, used to enrich error messages, if they occur
- Returns
- if
TypeCheckErrorthen there was an issue with the nested type, otherwise
None
- if
- Return type
Optional[TypeCheckError]