braincore.mixin.AllOfTypes

Contents

braincore.mixin.AllOfTypes#

braincore.mixin.AllOfTypes = typing.AllOfTypes#

All of types; AllOfTypes[X, Y] means both X and Y.

To define a union, use e.g. Union[int, str].

Details: - The arguments must be types and there must be at least one. - None as an argument is a special case and is replaced by type(None). - Unions of unions are flattened, e.g.:

AllOfTypes[AllOfTypes[int, str], float] == AllOfTypes[int, str, float]
  • Unions of a single argument vanish, e.g.:

    AllOfTypes[int] == int  # The constructor actually returns int
    
  • Redundant arguments are skipped, e.g.:

    AllOfTypes[int, str, int] == AllOfTypes[int, str]
    
  • When comparing unions, the argument order is ignored, e.g.:

    AllOfTypes[int, str] == AllOfTypes[str, int]
    
  • You cannot subclass or instantiate a AllOfTypes.

  • You can use Optional[X] as a shorthand for AllOfTypes[X, None].