apache_beam.typehints.native_type_compatibility module

Module to convert Python’s native typing types to Beam types.

apache_beam.typehints.native_type_compatibility.match_is_named_tuple(user_type)[source]
apache_beam.typehints.native_type_compatibility.extract_optional_type(user_type)[source]

Extracts the non-None type from Optional type user_type.

If user_type is not Optional, returns None

apache_beam.typehints.native_type_compatibility.is_any(typ)[source]
apache_beam.typehints.native_type_compatibility.is_new_type(typ)[source]
apache_beam.typehints.native_type_compatibility.is_forward_ref(typ)[source]
apache_beam.typehints.native_type_compatibility.convert_to_beam_type(typ)[source]

Convert a given typing type to a Beam type.

Parameters:typ (typing.Union[type, str]) – typing type or string literal representing a type.
Returns:The given type converted to a Beam type as far as we can do the conversion.
Return type:type
Raises:ValueError – The type was malformed.
apache_beam.typehints.native_type_compatibility.convert_to_beam_types(args)[source]

Convert the given list or dictionary of args to Beam types.

Parameters:
  • args – Either an iterable of types, or a dictionary where the values are
  • types.
Returns:

If given an iterable, a list of converted types. If given a dictionary, a dictionary with the same keys, and values which have been converted.

apache_beam.typehints.native_type_compatibility.convert_to_typing_type(typ)[source]

Converts a given Beam type to a typing type.

This is the reverse of convert_to_beam_type.

Parameters:typ – If a typehints.TypeConstraint, the type to convert. Otherwise, typ will be unchanged.
Returns:Converted version of typ, or unchanged.
Raises:ValueError – The type was malformed or could not be converted.
apache_beam.typehints.native_type_compatibility.convert_to_typing_types(args)[source]

Convert the given list or dictionary of args to typing types.

Parameters:
  • args – Either an iterable of types, or a dictionary where the values are
  • types.
Returns:

If given an iterable, a list of converted types. If given a dictionary, a dictionary with the same keys, and values which have been converted.