apache_beam.typehints.typehints module¶
Syntax & semantics for type-hinting custom-functions/PTransforms in the SDK.
This module defines type-hinting objects and the corresponding syntax for type-hinting function arguments, function return types, or PTransform object themselves. TypeHint’s defined in the module can be used to implement either static or run-time type-checking in regular Python code.
Type-hints are defined by ‘indexing’ a type-parameter into a defined CompositeTypeHint instance:
- ‘List[int]’.
Valid type-hints are partitioned into two categories: simple, and composite.
Simple type hints are type hints based on a subset of Python primitive types: int, bool, float, str, object, None, and bytes. No other primitive types are allowed.
Composite type-hints are reserved for hinting the types of container-like Python objects such as ‘list’. Composite type-hints can be parameterized by an inner simple or composite type-hint, using the ‘indexing’ syntax. In order to avoid conflicting with the namespace of the built-in container types, when specifying this category of type-hints, the first letter should be capitalized. The following composite type-hints are permitted. NOTE: ‘T’ can be any of the type-hints listed or a simple Python type:
- Any
- Union[T, T, T]
- Optional[T]
- Tuple[T, T]
- Tuple[T, …]
- List[T]
- KV[T, T]
- Dict[T, T]
- Set[T]
- Iterable[T]
- Iterator[T]
- Generator[T]
Type-hints can be nested, allowing one to define type-hints for complex types:
- ‘List[Tuple[int, int, str]]
In addition, type-hints can be used to implement run-time type-checking via the ‘type_check’ method on each TypeConstraint.
-
class
apache_beam.typehints.typehints.
TypeVariable
(name, use_name_in_eq=True)[source]¶ Bases:
apache_beam.typehints.typehints.AnyTypeConstraint
-
apache_beam.typehints.typehints.
WindowedValue
¶ alias of
apache_beam.typehints.typehints.WindowedTypeConstraint