apache_beam.typehints.trivial_inference module

Trivial type inference for simple functions.

For internal use only; no backwards-compatibility guarantees.

class apache_beam.typehints.trivial_inference.BoundMethod(func, type)[source]

Bases: future.types.newobject.newobject

Used to create a bound method when we only know the type of the instance.

Instantiates a bound method object.

Parameters:
class apache_beam.typehints.trivial_inference.Const(value)[source]

Bases: future.types.newobject.newobject

static unwrap(x)[source]
static unwrap_all(xs)[source]
class apache_beam.typehints.trivial_inference.FrameState(f, local_vars=None, stack=())[source]

Bases: future.types.newobject.newobject

Stores the state of the frame at a particular point of execution.

closure_type(i)[source]
const_type(i)[source]
copy()[source]
get_global(i)[source]
get_name(i)[source]
exception apache_beam.typehints.trivial_inference.TypeInferenceError[source]

Bases: exceptions.ValueError

Error to raise when type inference failed.

apache_beam.typehints.trivial_inference.element_type(hint)[source]

Returns the element type of a composite type.

apache_beam.typehints.trivial_inference.hashable(c)[source]
apache_beam.typehints.trivial_inference.infer_return_type(c, input_types, debug=False, depth=5)[source]

Analyses a callable to deduce its return type.

Parameters:
  • c – A Python callable to infer the return type of.
  • input_types – A sequence of inputs corresponding to the input types.
  • debug – Whether to print verbose debugging information.
  • depth – Maximum inspection depth during type inference.
Returns:

A TypeConstraint that that the return value of this function will (likely) satisfy given the specified inputs.

apache_beam.typehints.trivial_inference.infer_return_type_func(f, input_types, debug=False, depth=0)[source]

Analyses a function to deduce its return type.

Parameters:
  • f – A Python function object to infer the return type of.
  • input_types – A sequence of inputs corresponding to the input types.
  • debug – Whether to print verbose debugging information.
  • depth – Maximum inspection depth during type inference.
Returns:

A TypeConstraint that that the return value of this function will (likely) satisfy given the specified inputs.

Raises:

TypeInferenceError – if no type can be inferred.

apache_beam.typehints.trivial_inference.instance_to_type(o)[source]

Given a Python object o, return the corresponding type hint.

apache_beam.typehints.trivial_inference.key_value_types(kv_type)[source]

Returns the key and value type of a KV type.

apache_beam.typehints.trivial_inference.union(a, b)[source]

Returns the union of two types or Const values.

apache_beam.typehints.trivial_inference.union_list(xs, ys)[source]