apache_beam.typehints.trivial_inference module

Trivial type inference for simple functions.

For internal use only; no backwards-compatibility guarantees.

exception apache_beam.typehints.trivial_inference.TypeInferenceError[source]

Bases: ValueError

Error to raise when type inference failed.

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.union_list(xs, ys)[source]
class apache_beam.typehints.trivial_inference.Const(value)[source]

Bases: object

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

Bases: object

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

copy()[source]
const_type(i)[source]
get_closure(i)[source]
closure_type(i)[source]

Returns a TypeConstraint or Const.

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

Returns the union of two types or Const values.

apache_beam.typehints.trivial_inference.finalize_hints(type_hint)[source]

Sets type hint for empty data structures to Any.

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

Returns the element type of a composite type.

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

Returns the key and value type of a KV type.

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

Bases: object

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

Instantiates a bound method object.

Parameters:
  • func (types.FunctionType) – The method’s underlying function

  • type (type) – The class of the method.

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.