adorn.unit.python module

Representation of python’s std lib

class adorn.unit.python.Bool

Bases: adorn.unit.python.BuiltIn

Representation of python’s bool type

base_type

alias of bool

class adorn.unit.python.BuiltIn

Bases: adorn.unit.python.Python

Representation 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 TypeCheckError containing

the reason why the obj didn’t pass the additional checks, otherwise None

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 bool from being confused as an int.

class adorn.unit.python.Float

Bases: adorn.unit.python.BuiltIn

Representation of python’s float type

base_type

alias of float

class adorn.unit.python.Int

Bases: adorn.unit.python.BuiltIn

Representation of python’s int type

classmethod additional_checks(orchestrator, obj)

Type checks specific to int

Exceptions:
Parameters
  • orchestrator (Orchestrator) – container of all types, unused

  • obj (Any) – an instance that will have additional type checking performed against it

Returns

either a TypeCheckError containing

the reason why the obj didn’t pass the additional checks, otherwise None

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 bool from being confused as an int.

class adorn.unit.python.Python

Bases: adorn.unit.simple.Simple

Unit that 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 key is part of python’s std lib,

then the type that is meant to represent the python std lib type will be returned, otherwise None

Return type

Optional[type]

class adorn.unit.python.Ret

Bases: adorn.unit.python.Wrapper

Represents Python’s Set type

class adorn.unit.python.Rict

Bases: adorn.unit.python.Wrapper

Represents Python’s Dict type

class adorn.unit.python.Rnion

Bases: adorn.unit.python.Wrapper

Represents Python’s Union type

class adorn.unit.python.Rterable

Bases: adorn.unit.python.Wrapper

Representation of python’s Iterable type

class adorn.unit.python.Ruple

Bases: adorn.unit.python.Wrapper

Represents Python’s Tuple type

Note

This representation of Tuple does not handle tuples of arbitrary length. The full length of the Tuple must be specified in the type signature at instantiation time.

class adorn.unit.python.Str

Bases: adorn.unit.python.BuiltIn

Representation of python’s str type

base_type

alias of str

class adorn.unit.python.Wrapper

Bases: adorn.unit.python.Python

Base class for python wrapper types.

static is_hashable(target_cls, target_arg, orchestrator, obj)

Check if a given type may be hashed.

Exceptions:
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 TypeCheckError then there was

an issue with the nested type, otherwise None

Return type

Optional[TypeCheckError]