beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject [03/50] [abbrv] incubator-beam git commit: Move all files to apache_beam folder
Date Tue, 14 Jun 2016 23:12:38 GMT
http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/b14dfadd/sdks/python/google/cloud/dataflow/typehints/typed_pipeline_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/google/cloud/dataflow/typehints/typed_pipeline_test.py b/sdks/python/google/cloud/dataflow/typehints/typed_pipeline_test.py
deleted file mode 100644
index 67362dc..0000000
--- a/sdks/python/google/cloud/dataflow/typehints/typed_pipeline_test.py
+++ /dev/null
@@ -1,248 +0,0 @@
-# Copyright 2016 Google Inc. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Unit tests for the type-hint objects and decorators."""
-import inspect
-import unittest
-
-
-import google.cloud.dataflow as df
-from google.cloud.dataflow import pvalue
-from google.cloud.dataflow import typehints
-from google.cloud.dataflow.transforms.util import assert_that, equal_to
-from google.cloud.dataflow.typehints import WithTypeHints
-from google.cloud.dataflow.utils.options import OptionsContext
-from google.cloud.dataflow.utils.options import PipelineOptions
-
-# These test often construct a pipeline as value | PTransform to test side
-# effects (e.g. errors).
-# pylint: disable=expression-not-assigned
-
-
-class MainInputTest(unittest.TestCase):
-
-  def test_bad_main_input(self):
-    @typehints.with_input_types(str, int)
-    def repeat(s, times):
-      return s * times
-    with self.assertRaises(typehints.TypeCheckError):
-      [1, 2, 3] | df.Map(repeat, 3)
-
-  def test_non_function(self):
-    result = ['a', 'bb', 'c'] | df.Map(str.upper)
-    self.assertEqual(['A', 'BB', 'C'], sorted(result))
-
-    result = ['xa', 'bbx', 'xcx'] | df.Map(str.strip, 'x')
-    self.assertEqual(['a', 'bb', 'c'], sorted(result))
-
-    result = ['1', '10', '100'] | df.Map(int)
-    self.assertEqual([1, 10, 100], sorted(result))
-
-    result = ['1', '10', '100'] | df.Map(int, 16)
-    self.assertEqual([1, 16, 256], sorted(result))
-
-    with self.assertRaises(typehints.TypeCheckError):
-      [1, 2, 3] | df.Map(str.upper)
-
-  def test_loose_bounds(self):
-    @typehints.with_input_types(typehints.Union[int, float, long])
-    @typehints.with_output_types(basestring)
-    def format_number(x):
-      return '%g' % x
-    result = [1, 2, 3] | df.Map(format_number)
-    self.assertEqual(['1', '2', '3'], sorted(result))
-
-  def test_typed_dofn_class(self):
-    @typehints.with_input_types(int)
-    @typehints.with_output_types(str)
-    class MyDoFn(df.DoFn):
-      def process(self, context):
-        return [str(context.element)]
-
-    result = [1, 2, 3] | df.ParDo(MyDoFn())
-    self.assertEqual(['1', '2', '3'], sorted(result))
-
-    with self.assertRaises(typehints.TypeCheckError):
-      ['a', 'b', 'c'] | df.ParDo(MyDoFn())
-
-    with self.assertRaises(typehints.TypeCheckError):
-      [1, 2, 3] | (df.ParDo(MyDoFn()) | df.ParDo('again', MyDoFn()))
-
-  def test_typed_dofn_instance(self):
-    class MyDoFn(df.DoFn):
-      def process(self, context):
-        return [str(context.element)]
-    my_do_fn = MyDoFn().with_input_types(int).with_output_types(str)
-
-    result = [1, 2, 3] | df.ParDo(my_do_fn)
-    self.assertEqual(['1', '2', '3'], sorted(result))
-
-    with self.assertRaises(typehints.TypeCheckError):
-      ['a', 'b', 'c'] | df.ParDo(my_do_fn)
-
-    with self.assertRaises(typehints.TypeCheckError):
-      [1, 2, 3] | (df.ParDo(my_do_fn) | df.ParDo('again', my_do_fn))
-
-
-class SideInputTest(unittest.TestCase):
-
-  def _run_repeat_test(self, repeat):
-    self._run_repeat_test_good(repeat)
-    self._run_repeat_test_bad(repeat)
-
-  @OptionsContext(pipeline_type_check=True)
-  def _run_repeat_test_good(self, repeat):
-    # As a positional argument.
-    result = ['a', 'bb', 'c'] | df.Map(repeat, 3)
-    self.assertEqual(['aaa', 'bbbbbb', 'ccc'], sorted(result))
-
-    # As a keyword argument.
-    result = ['a', 'bb', 'c'] | df.Map(repeat, times=3)
-    self.assertEqual(['aaa', 'bbbbbb', 'ccc'], sorted(result))
-
-  def _run_repeat_test_bad(self, repeat):
-    # Various mismatches.
-    with self.assertRaises(typehints.TypeCheckError):
-      ['a', 'bb', 'c'] | df.Map(repeat, 'z')
-    with self.assertRaises(typehints.TypeCheckError):
-      ['a', 'bb', 'c'] | df.Map(repeat, times='z')
-    with self.assertRaises(typehints.TypeCheckError):
-      ['a', 'bb', 'c'] | df.Map(repeat, 3, 4)
-    if not inspect.getargspec(repeat).defaults:
-      with self.assertRaises(typehints.TypeCheckError):
-        ['a', 'bb', 'c'] | df.Map(repeat)
-
-  def test_basic_side_input_hint(self):
-    @typehints.with_input_types(str, int)
-    def repeat(s, times):
-      return s * times
-    self._run_repeat_test(repeat)
-
-  def test_keyword_side_input_hint(self):
-    @typehints.with_input_types(str, times=int)
-    def repeat(s, times):
-      return s * times
-    self._run_repeat_test(repeat)
-
-  def test_default_typed_hint(self):
-    @typehints.with_input_types(str, int)
-    def repeat(s, times=3):
-      return s * times
-    self._run_repeat_test(repeat)
-
-  def test_default_untyped_hint(self):
-    @typehints.with_input_types(str)
-    def repeat(s, times=3):
-      return s * times
-    # No type checking on dfault arg.
-    self._run_repeat_test_good(repeat)
-
-  @OptionsContext(pipeline_type_check=True)
-  def test_varargs_side_input_hint(self):
-    @typehints.with_input_types(str, int)
-    def repeat(s, *times):
-      return s * times[0]
-
-    result = ['a', 'bb', 'c'] | df.Map(repeat, 3)
-    self.assertEqual(['aaa', 'bbbbbb', 'ccc'], sorted(result))
-
-  # TODO(robertwb): Support partially defined varargs.
-  # with self.assertRaises(typehints.TypeCheckError):
-  #   ['a', 'bb', 'c'] | df.Map(repeat, 'z')
-
-  def test_deferred_side_inputs(self):
-    @typehints.with_input_types(str, int)
-    def repeat(s, times):
-      return s * times
-    p = df.Pipeline(options=PipelineOptions([]))
-    main_input = p | df.Create(['a', 'bb', 'c'])
-    side_input = p | df.Create('side', [3])
-    result = main_input | df.Map(repeat, pvalue.AsSingleton(side_input))
-    assert_that(result, equal_to(['aaa', 'bbbbbb', 'ccc']))
-    p.run()
-
-    bad_side_input = p | df.Create('bad_side', ['z'])
-    with self.assertRaises(typehints.TypeCheckError):
-      main_input | df.Map('again', repeat, pvalue.AsSingleton(bad_side_input))
-
-  def test_deferred_side_input_iterable(self):
-    @typehints.with_input_types(str, typehints.Iterable[str])
-    def concat(glue, items):
-      return glue.join(sorted(items))
-    p = df.Pipeline(options=PipelineOptions([]))
-    main_input = p | df.Create(['a', 'bb', 'c'])
-    side_input = p | df.Create('side', ['x', 'y', 'z'])
-    result = main_input | df.Map(concat, pvalue.AsIter(side_input))
-    assert_that(result, equal_to(['xayaz', 'xbbybbz', 'xcycz']))
-    p.run()
-
-    bad_side_input = p | df.Create('bad_side', [1, 2, 3])
-    with self.assertRaises(typehints.TypeCheckError):
-      main_input | df.Map('fail', concat, pvalue.AsIter(bad_side_input))
-
-
-class CustomTransformTest(unittest.TestCase):
-
-  class CustomTransform(df.PTransform):
-
-    def _extract_input_pvalues(self, pvalueish):
-      return pvalueish, (pvalueish['in0'], pvalueish['in1'])
-
-    def apply(self, pvalueish):
-      return {'out0': pvalueish['in0'], 'out1': pvalueish['in1']}
-
-    # TODO(robertwb): (typecheck) Make these the default?
-    def with_input_types(self, *args, **kwargs):
-      return WithTypeHints.with_input_types(self, *args, **kwargs)
-
-    def with_output_types(self, *args, **kwargs):
-      return WithTypeHints.with_output_types(self, *args, **kwargs)
-
-  test_input = {'in0': ['a', 'b', 'c'], 'in1': [1, 2, 3]}
-
-  def check_output(self, result):
-    self.assertEqual(['a', 'b', 'c'], sorted(result['out0']))
-    self.assertEqual([1, 2, 3], sorted(result['out1']))
-
-  def test_custom_transform(self):
-    self.check_output(self.test_input | self.CustomTransform())
-
-  def test_keyword_type_hints(self):
-    self.check_output(
-        self.test_input | self.CustomTransform().with_input_types(
-            in0=str, in1=int))
-    self.check_output(
-        self.test_input | self.CustomTransform().with_input_types(in0=str))
-    self.check_output(
-        self.test_input | self.CustomTransform().with_output_types(
-            out0=str, out1=int))
-    with self.assertRaises(typehints.TypeCheckError):
-      self.test_input | self.CustomTransform().with_input_types(in0=int)
-    with self.assertRaises(typehints.TypeCheckError):
-      self.test_input | self.CustomTransform().with_output_types(out0=int)
-
-  def test_flat_type_hint(self):
-    # Type hint is applied to both.
-    ({'in0': ['a', 'b', 'c'], 'in1': ['x', 'y', 'z']}
-     | self.CustomTransform().with_input_types(str))
-    with self.assertRaises(typehints.TypeCheckError):
-      self.test_input | self.CustomTransform().with_input_types(str)
-    with self.assertRaises(typehints.TypeCheckError):
-      self.test_input | self.CustomTransform().with_input_types(int)
-    with self.assertRaises(typehints.TypeCheckError):
-      self.test_input | self.CustomTransform().with_output_types(int)
-
-
-if __name__ == '__main__':
-  unittest.main()

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/b14dfadd/sdks/python/google/cloud/dataflow/typehints/typehints.py
----------------------------------------------------------------------
diff --git a/sdks/python/google/cloud/dataflow/typehints/typehints.py b/sdks/python/google/cloud/dataflow/typehints/typehints.py
deleted file mode 100644
index f1b3f53..0000000
--- a/sdks/python/google/cloud/dataflow/typehints/typehints.py
+++ /dev/null
@@ -1,1054 +0,0 @@
-# Copyright 2016 Google Inc. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Syntax and 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 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.
-
-"""
-
-import collections
-import copy
-import types
-
-
-# A set of the built-in Python types we don't support, guiding the users
-# to templated (upper-case) versions instead.
-DISALLOWED_PRIMITIVE_TYPES = (list, set, tuple, dict)
-
-
-class SimpleTypeHintError(TypeError):
-  pass
-
-
-class CompositeTypeHintError(TypeError):
-  pass
-
-
-class GetitemConstructor(type):
-  """A metaclass that makes Cls[arg] an alias for Cls(arg)."""
-  def __getitem__(cls, arg):
-    return cls(arg)
-
-
-class TypeConstraint(object):
-
-  """The base-class for all created type-constraints defined below.
-
-  A TypeConstraint is the result of parameterizing a CompositeTypeHint with
-  with one of the allowed Python types or another CompositeTypeHint. It
-  binds and enforces a specific version of a generalized TypeHint.
-  """
-
-  def _consistent_with_check_(self, sub):
-    """Returns whether sub is consistent with self.
-
-    Has the same relationship to is_consistent_with() as
-    __subclasscheck__ does for issubclass().
-
-    Not meant to be called directly; call is_consistent_with(sub, self)
-    instead.
-
-    Implementation may assume that maybe_sub_type is not Any
-    and has been normalized.
-    """
-    raise NotImplementedError
-
-  def type_check(self, instance):
-    """Determines if the type of 'instance' satisfies this type constraint.
-
-    Args:
-      instance: An instance of a Python object.
-
-    Raises:
-      TypeError: The passed 'instance' doesn't satisfy this TypeConstraint.
-        Subclasses of TypeConstraint are free to raise any of the subclasses of
-        TypeError defined above, depending on the manner of the type hint error.
-
-    All TypeConstraint sub-classes must define this method in other for the
-    class object to be created.
-    """
-    raise NotImplementedError
-
-  def match_type_variables(self, unused_concrete_type):
-    return {}
-
-  def bind_type_variables(self, unused_bindings):
-    return self
-
-  def _inner_types(self):
-    """Iterates over the inner types of the composite type."""
-    return []
-
-  def visit(self, visitor, visitor_arg):
-    """Visitor method to visit all inner types of a composite type.
-
-    Args:
-      visitor: A callable invoked for all nodes in the type tree comprising
-        a composite type. The visitor will be called with the node visited
-        and the visitor argument specified here.
-      visitor_arg: Visitor callback second argument.
-    """
-    visitor(self, visitor_arg)
-    for t in self._inner_types():
-      if isinstance(t, TypeConstraint):
-        t.visit(visitor, visitor_arg)
-      else:
-        visitor(t, visitor_arg)
-
-
-def match_type_variables(type_constraint, concrete_type):
-  if isinstance(type_constraint, TypeConstraint):
-    return type_constraint.match_type_variables(concrete_type)
-  else:
-    return {}
-
-
-def bind_type_variables(type_constraint, bindings):
-  if isinstance(type_constraint, TypeConstraint):
-    return type_constraint.bind_type_variables(bindings)
-  else:
-    return type_constraint
-
-
-class SequenceTypeConstraint(TypeConstraint):
-  """A common base-class for all sequence related type-constraint classes.
-
-  A sequence is defined as an arbitrary length homogeneous container type. Type
-  hints which fall under this category include: List[T], Set[T], Iterable[T],
-  and Tuple[T, ...].
-
-  Sub-classes may need to override '_consistent_with_check_' if a particular
-  sequence requires special handling with respect to type compatibility.
-
-  Attributes:
-    inner_type: The type which every element in the sequence should be an
-      instance of.
-  """
-
-  def __init__(self, inner_type, sequence_type):
-    self.inner_type = inner_type
-    self._sequence_type = sequence_type
-
-  def __eq__(self, other):
-    return (isinstance(other, SequenceTypeConstraint)
-            and type(self) == type(other)
-            and self.inner_type == other.inner_type)
-
-  def __hash__(self):
-    return hash(self.inner_type) ^ 13 * hash(type(self))
-
-  def _inner_types(self):
-    yield self.inner_type
-
-  def _consistent_with_check_(self, sub):
-    return (isinstance(sub, self.__class__)
-            and is_consistent_with(sub.inner_type, self.inner_type))
-
-  def type_check(self, sequence_instance):
-    if not isinstance(sequence_instance, self._sequence_type):
-      raise CompositeTypeHintError(
-          "%s type-constraint violated. Valid object instance "
-          "must be of type '%s'. Instead, an instance of '%s' "
-          "was received."
-          % (self._sequence_type.__name__.title(),
-             self._sequence_type.__name__.lower(),
-             sequence_instance.__class__.__name__))
-
-    for index, elem in enumerate(sequence_instance):
-      try:
-        check_constraint(self.inner_type, elem)
-      except SimpleTypeHintError as e:
-        raise CompositeTypeHintError(
-            '%s hint type-constraint violated. The type of element #%s in '
-            'the passed %s is incorrect. Expected an instance of type %s, '
-            'instead received an instance of type %s.' %
-            (repr(self), index, _unified_repr(self._sequence_type),
-             _unified_repr(self.inner_type), elem.__class__.__name__))
-      except CompositeTypeHintError as e:
-        raise CompositeTypeHintError(
-            '%s hint type-constraint violated. The type of element #%s in '
-            'the passed %s is incorrect: %s'
-            % (repr(self), index, self._sequence_type.__name__, e))
-
-  def match_type_variables(self, concrete_type):
-    if isinstance(concrete_type, SequenceTypeConstraint):
-      return match_type_variables(self.inner_type, concrete_type.inner_type)
-    else:
-      return {}
-
-  def bind_type_variables(self, bindings):
-    bound_inner_type = bind_type_variables(self.inner_type, bindings)
-    if bound_inner_type == self.inner_type:
-      return self
-    else:
-      bound_self = copy.copy(self)
-      bound_self.inner_type = bound_inner_type
-      return bound_self
-
-
-class CompositeTypeHint(object):
-  """The base-class for all created type-hint classes defined below.
-
-  CompositeTypeHint's serve primarily as TypeConstraint factories. They are
-  only required to define a single method: '__getitem__' which should return a
-  parameterized TypeConstraint, that can be used to enforce static or run-time
-  type-checking.
-
-  '__getitem__' is used as a factory function in order to provide a familiar
-  API for defining type-hints. The ultimate result is that one will be able to
-  use: CompositeTypeHint[type_parameter] to create a type-hint object that
-  behaves like any other Python object. This allows one to create
-  'type-aliases' by assigning the returned type-hints to a variable.
-
-    * Example: 'Coordinates = List[Tuple[int, int]]'
-  """
-
-  def __getitem___(self, py_type):
-    """Given a type creates a TypeConstraint instance parameterized by the type.
-
-    This function serves as a factory function which creates TypeConstraint
-    instances. Additionally, implementations by sub-classes should perform any
-    sanity checking of the passed types in this method in order to rule-out
-    disallowed behavior. Such as, attempting to create a TypeConstraint whose
-    parameterized type is actually an object instance.
-
-    Args:
-      py_type: An instance of a Python type or TypeConstraint.
-
-    Returns: An instance of a custom TypeConstraint for this CompositeTypeHint.
-
-    Raises:
-      TypeError: If the passed type violates any contraints for this particular
-        TypeHint.
-    """
-    raise NotImplementedError
-
-
-def validate_composite_type_param(type_param, error_msg_prefix):
-  """Determines if an object is a valid type parameter to a CompositeTypeHint.
-
-  Implements sanity checking to disallow things like:
-    * List[1, 2, 3] or Dict[5].
-
-  Args:
-    type_param: An object instance.
-    error_msg_prefix: A string prefix used to format an error message in the
-      case of an exception.
-
-  Raises:
-    TypeError: If the passed 'type_param' is not a valid type parameter for a
-      CompositeTypeHint.
-  """
-  # Must either be a TypeConstraint instance or a basic Python type.
-  is_not_type_constraint = (
-      not isinstance(type_param, (type, types.ClassType, TypeConstraint))
-      and type_param is not None)
-  is_forbidden_type = (isinstance(type_param, type) and
-                       type_param in DISALLOWED_PRIMITIVE_TYPES)
-
-  if is_not_type_constraint or is_forbidden_type:
-    raise TypeError('%s must be a non-sequence, a type, or a TypeConstraint. %s'
-                    ' is an instance of %s.' % (error_msg_prefix, type_param,
-                                                type_param.__class__.__name__))
-
-
-def _unified_repr(o):
-  """Given an object return a qualified name for the object.
-
-  This function closely mirrors '__qualname__' which was introduced in
-  Python 3.3. It is used primarily to format types or object instances for
-  error messages.
-
-  Args:
-    o: An instance of a TypeConstraint or a type.
-
-  Returns:
-    A qualified name for the passed Python object fit for string formatting.
-  """
-  return repr(o) if isinstance(o, (TypeConstraint, types.NoneType)) else o.__name__
-
-
-def check_constraint(type_constraint, object_instance):
-  """Determine if the passed type instance satisfies the TypeConstraint.
-
-  When examining a candidate type for constraint satisfaction in
-  'type_check', all CompositeTypeHint's eventually call this function. This
-  function may end up being called recursively if the hinted type of a
-  CompositeTypeHint is another CompositeTypeHint.
-
-  Args:
-    type_constraint: An instance of a TypeConstraint or a built-in Python type.
-    object_instance: An object instance.
-
-  Raises:
-    SimpleTypeHintError: If 'type_constraint' is a one of the allowed primitive
-      Python types and 'object_instance' isn't an instance of this type.
-    CompositeTypeHintError: If 'type_constraint' is a TypeConstraint object and
-      'object_instance' does not satisfy its constraint.
-  """
-  if type_constraint is None and object_instance is None:
-    return
-  elif isinstance(type_constraint, TypeConstraint):
-    type_constraint.type_check(object_instance)
-  elif type_constraint is None:
-    # TODO(robertwb): Fix uses of None for Any.
-    pass
-  elif not isinstance(type_constraint, type):
-    raise RuntimeError("bad type: %s" % (type_constraint,))
-  elif not isinstance(object_instance, type_constraint):
-    raise SimpleTypeHintError
-
-
-class AnyTypeConstraint(TypeConstraint):
-  """An Any type-hint.
-
-  Any is intended to be used as a "don't care" when hinting the types of
-  function arguments or return types. All other TypeConstraint's are equivalent
-  to 'Any', and its 'type_check' method is a no-op.
-  """
-
-  def __repr__(self):
-    return 'Any'
-
-  def type_check(self, instance):
-    pass
-
-
-class TypeVariable(AnyTypeConstraint):
-
-  def __init__(self, name):
-    self.name = name
-
-  def __repr__(self):
-    return 'TypeVariable[%s]' % self.name
-
-  def match_type_variables(self, concrete_type):
-    return {self: concrete_type}
-
-  def bind_type_variables(self, bindings):
-    return bindings.get(self, self)
-
-
-class UnionHint(CompositeTypeHint):
-  """A Union type-hint. Union[X, Y] accepts instances of type X OR type Y.
-
-  Duplicate type parameters are ignored. Additonally, Nested Union hints will
-  be flattened out. For example:
-
-    * Union[Union[str, int], bool] -> Union[str, int, bool]
-
-  A candidate type instance satisfies a UnionConstraint if it is an
-  instance of any of the parameterized 'union_types' for a Union.
-
-  Union[X] is disallowed, and all type parameters will be sanity checked to
-  ensure compatibility with nested type-hints.
-
-  When comparing two Union hints, ordering is enforced before comparison.
-
-    * Union[int, str] == Union[str, int]
-  """
-
-  class UnionConstraint(TypeConstraint):
-
-    def __init__(self, union_types):
-      self.union_types = set(union_types)
-
-    def __eq__(self, other):
-      return (isinstance(other, UnionHint.UnionConstraint)
-              and self.union_types == other.union_types)
-
-    def __hash__(self):
-      return 1 + sum(hash(t) for t in self.union_types)
-
-    def __repr__(self):
-      # Sorting the type name strings simplifies unit tests.
-      return 'Union[%s]' % (', '.join(sorted(_unified_repr(t)
-                                             for t in self.union_types)))
-
-    def _inner_types(self):
-      for t in self.union_types:
-        yield t
-
-    def _consistent_with_check_(self, sub):
-      if isinstance(sub, UnionConstraint):
-        # A union type is compatible if every possible type is compatible.
-        # E.g. Union[A, B, C] > Union[A, B].
-        return all(is_consistent_with(elem, self)
-                   for elem in sub.union_types)
-      else:
-        # Other must be compatible with at least one of this union's subtypes.
-        # E.g. Union[A, B, C] > T if T > A or T > B or T > C.
-        return any(is_consistent_with(sub, elem)
-                   for elem in self.union_types)
-
-    def type_check(self, instance):
-      error_msg = ''
-      for t in self.union_types:
-        try:
-          check_constraint(t, instance)
-          return
-        except TypeError as e:
-          error_msg = str(e)
-          continue
-
-      raise CompositeTypeHintError(
-          '%s type-constraint violated. Expected an instance of one of: %s, '
-          'received %s instead.%s'
-          % (repr(self),
-             tuple(sorted(_unified_repr(t) for t in self.union_types)),
-             instance.__class__.__name__, error_msg))
-
-  def __getitem__(self, type_params):
-    if not isinstance(type_params, (collections.Sequence, set)):
-      raise TypeError('Cannot create Union without a sequence of types.')
-
-    # Flatten nested Union's and duplicated repeated type hints.
-    params = set()
-    for t in type_params:
-      validate_composite_type_param(
-          t, error_msg_prefix='All parameters to a Union hint'
-      )
-
-      if isinstance(t, self.UnionConstraint):
-        params |= t.union_types
-      else:
-        params.add(t)
-
-    if Any in params:
-      return Any
-    elif len(params) == 1:
-      return iter(params).next()
-    else:
-      return self.UnionConstraint(params)
-
-
-UnionConstraint = UnionHint.UnionConstraint
-
-
-class OptionalHint(UnionHint):
-  """An Option type-hint. Optional[X] accepts instances of X or None.
-
-  The Optional[X] factory function proxies to Union[X, None]
-  """
-
-  def __getitem__(self, py_type):
-    # A single type must have been passed.
-    if isinstance(py_type, collections.Sequence):
-      raise TypeError('An Option type-hint only accepts a single type '
-                      'parameter.')
-
-    return Union[py_type, None]
-
-
-class TupleHint(CompositeTypeHint):
-  """A Tuple type-hint.
-
-  Tuple can accept 1 or more type-hint parameters.
-
-  Tuple[X, Y] represents a tuple of *exactly* two elements, with the first
-  being of type 'X' and the second an instance of type 'Y'.
-
-    * (1, 2) satisfies Tuple[int, int]
-
-  Additionally, one is able to type-hint an arbitary length, homogeneous tuple
-  by passing the Ellipsis (...) object as the second parameter.
-
-  As an example, Tuple[str, ...] indicates a tuple of any length with each
-  element being an instance of 'str'.
-  """
-
-  class TupleSequenceConstraint(SequenceTypeConstraint):
-
-    def __init__(self, type_param):
-      super(TupleHint.TupleSequenceConstraint, self).__init__(type_param,
-                                                              tuple)
-
-    def __repr__(self):
-      return 'Tuple[%s, ...]' % _unified_repr(self.inner_type)
-
-    def _consistent_with_check_(self, sub):
-      if isinstance(sub, TupleConstraint):
-        # E.g. Tuple[A, B] < Tuple[C, ...] iff A < C and B < C.
-        return all(is_consistent_with(elem, self.inner_type)
-                   for elem in sub.tuple_types)
-      else:
-        return super(TupleSequenceConstraint, self)._consistent_with_check_(sub)
-
-  class TupleConstraint(TypeConstraint):
-
-    def __init__(self, type_params):
-      self.tuple_types = tuple(type_params)
-
-    def __eq__(self, other):
-      return (isinstance(other, TupleHint.TupleConstraint)
-              and self.tuple_types == other.tuple_types)
-
-    def __hash__(self):
-      return hash(self.tuple_types)
-
-    def __repr__(self):
-      return 'Tuple[%s]' % (', '.join(_unified_repr(t)
-                                      for t in self.tuple_types))
-
-    def _inner_types(self):
-      for t in self.tuple_types:
-        yield t
-
-    def _consistent_with_check_(self, sub):
-      return (isinstance(sub, self.__class__)
-              and len(sub.tuple_types) == len(self.tuple_types)
-              and all(is_consistent_with(sub_elem, elem)
-                      for sub_elem, elem
-                      in zip(sub.tuple_types, self.tuple_types)))
-
-    def type_check(self, tuple_instance):
-      if not isinstance(tuple_instance, tuple):
-        raise CompositeTypeHintError(
-            "Tuple type constraint violated. Valid object instance must be of "
-            "type 'tuple'. Instead, an instance of '%s' was received."
-            % tuple_instance.__class__.__name__)
-
-      if len(tuple_instance) != len(self.tuple_types):
-        raise CompositeTypeHintError(
-            'Passed object instance is of the proper type, but differs in '
-            'length from the hinted type. Expected a tuple of length %s, '
-            'received a tuple of length %s.'
-            % (len(self.tuple_types), len(tuple_instance)))
-
-      for type_pos, (expected, actual) in enumerate(zip(self.tuple_types,
-                                                        tuple_instance)):
-        try:
-          check_constraint(expected, actual)
-          continue
-        except SimpleTypeHintError:
-          raise CompositeTypeHintError(
-              '%s hint type-constraint violated. The type of element #%s in '
-              'the passed tuple is incorrect. Expected an instance of '
-              'type %s, instead received an instance of type %s.'
-              % (repr(self), type_pos, _unified_repr(expected),
-                 actual.__class__.__name__))
-        except CompositeTypeHintError as e:
-          raise CompositeTypeHintError(
-              '%s hint type-constraint violated. The type of element #%s in '
-              'the passed tuple is incorrect. %s'
-              % (repr(self), type_pos, e))
-
-    def match_type_variables(self, concrete_type):
-      bindings = {}
-      if isinstance(concrete_type, TupleConstraint):
-        for a, b in zip(self.tuple_types, concrete_type.tuple_types):
-          bindings.update(match_type_variables(a, b))
-      return bindings
-
-    def bind_type_variables(self, bindings):
-      bound_tuple_types = tuple(
-          bind_type_variables(t, bindings) for t in self.tuple_types)
-      if bound_tuple_types == self.tuple_types:
-        return self
-      else:
-        return Tuple[bound_tuple_types]
-
-  def __getitem__(self, type_params):
-    ellipsis = False
-
-    if not isinstance(type_params, collections.Iterable):
-      # Special case for hinting tuples with arity-1.
-      type_params = (type_params,)
-
-    if type_params and type_params[-1] == Ellipsis:
-      if len(type_params) != 2:
-        raise TypeError('Ellipsis can only be used to type-hint an arbitrary '
-                        'length tuple of containing a single type: '
-                        'Tuple[A, ...].')
-      # Tuple[A, ...] indicates an arbitary length homogeneous tuple.
-      type_params = type_params[:1]
-      ellipsis = True
-
-    for t in type_params:
-      validate_composite_type_param(
-          t,
-          error_msg_prefix='All parameters to a Tuple hint'
-      )
-
-    if ellipsis:
-      return self.TupleSequenceConstraint(type_params[0])
-    else:
-      return self.TupleConstraint(type_params)
-
-
-TupleConstraint = TupleHint.TupleConstraint
-TupleSequenceConstraint = TupleHint.TupleSequenceConstraint
-
-
-class ListHint(CompositeTypeHint):
-  """A List type-hint.
-
-  List[X] represents an instance of a list populated by a single homogeneous
-  type. The parameterized type 'X' can either be a built-in Python type or an
-  instance of another TypeConstraint.
-
-    * ['1', '2', '3'] satisfies List[str]
-  """
-
-  class ListConstraint(SequenceTypeConstraint):
-
-    def  __init__(self, list_type):
-      super(ListHint.ListConstraint, self).__init__(list_type, list)
-
-    def __repr__(self):
-      return 'List[%s]' % _unified_repr(self.inner_type)
-
-  def __getitem__(self, t):
-    validate_composite_type_param(t, error_msg_prefix='Parameter to List hint')
-
-    return self.ListConstraint(t)
-
-
-ListConstraint = ListHint.ListConstraint
-
-
-class KVHint(CompositeTypeHint):
-  """A KV type-hint, represents a Key-Value pair of a particular type.
-
-  Internally, KV[X, Y] proxies to Tuple[X, Y]. A KV type-hint accepts only
-  accepts exactly two type-parameters. The first represents the required
-  key-type and the second the required value-type.
-  """
-
-  def __getitem__(self, type_params):
-    if not isinstance(type_params, tuple):
-      raise TypeError('Parameter to KV type-hint must be a tuple of types: '
-                      'KV[.., ..].')
-
-    if len(type_params) != 2:
-      raise TypeError(
-          'Length of parameters to a KV type-hint must be exactly 2. Passed '
-          'parameters: %s, have a length of %s.' %
-          (type_params, len(type_params))
-      )
-
-    return Tuple[type_params]
-
-
-def key_value_types(kv):
-  """Returns the key and value type of a KV type-hint.
-
-  Args:
-    kv: An instance of a TypeConstraint sub-class.
-  Returns:
-    A tuple: (key_type, value_type) if the passed type-hint is an instance of a
-    KV type-hint, and (Any, Any) otherwise.
-  """
-  if isinstance(kv, TupleHint.TupleConstraint):
-    return kv.tuple_types
-  return Any, Any
-
-
-class DictHint(CompositeTypeHint):
-  """A Dict type-hint.
-
-  Dict[K, V] Represents a dictionary where all keys are of a particular type
-  and all values are of another (possible the same) type.
-  """
-
-  class DictConstraint(TypeConstraint):
-
-    def __init__(self, key_type, value_type):
-      self.key_type = key_type
-      self.value_type = value_type
-
-    def __repr__(self):
-      return 'Dict[%s, %s]' % (_unified_repr(self.key_type),
-                               _unified_repr(self.value_type))
-
-    def __eq__(self, other):
-      return (type(self) == type(other)
-              and self.key_type == other.key_type
-              and self.value_type == other.value_type)
-
-    def __hash__(self):
-      return hash((type(self), self.key_type, self.value_type))
-
-    def _inner_types(self):
-      yield self.key_type
-      yield self.value_type
-
-    def _consistent_with_check_(self, sub):
-      return (isinstance(sub, self.__class__)
-              and is_consistent_with(sub.key_type, self.key_type)
-              and is_consistent_with(sub.key_type, self.key_type))
-
-    def _raise_hint_exception_or_inner_exception(self, is_key,
-                                                 incorrect_instance,
-                                                 inner_error_message=''):
-      incorrect_type = 'values' if not is_key else 'keys'
-      hinted_type = self.value_type if not is_key else self.key_type
-      if inner_error_message:
-        raise CompositeTypeHintError(
-            '%s hint %s-type constraint violated. All %s should be of type '
-            '%s. Instead: %s'
-            % (repr(self), incorrect_type[:-1], incorrect_type,
-               _unified_repr(hinted_type), inner_error_message)
-        )
-      else:
-        raise CompositeTypeHintError(
-            '%s hint %s-type constraint violated. All %s should be of '
-            'type %s. Instead, %s is of type %s.'
-            % (repr(self), incorrect_type[:-1], incorrect_type,
-               _unified_repr(hinted_type),
-               incorrect_instance, incorrect_instance.__class__.__name__)
-        )
-
-    def type_check(self, dict_instance):
-      if not isinstance(dict_instance, dict):
-        raise CompositeTypeHintError(
-            'Dict type-constraint violated. All passed instances must be of '
-            'type dict. %s is of type %s.'
-            % (dict_instance, dict_instance.__class__.__name__))
-
-      for key, value in dict_instance.iteritems():
-        try:
-          check_constraint(self.key_type, key)
-        except CompositeTypeHintError as e:
-          self._raise_hint_exception_or_inner_exception(True, key, str(e))
-        except SimpleTypeHintError:
-          self._raise_hint_exception_or_inner_exception(True, key)
-
-        try:
-          check_constraint(self.value_type, value)
-        except CompositeTypeHintError as e:
-          self._raise_hint_exception_or_inner_exception(False, value, str(e))
-        except SimpleTypeHintError:
-          self._raise_hint_exception_or_inner_exception(False, value)
-
-    def match_type_variables(self, concrete_type):
-      if isinstance(concrete_type, DictConstraint):
-        bindings = {}
-        bindings.update(
-            match_type_variables(self.key_type, concrete_type.key_type))
-        bindings.update(
-            match_type_variables(self.value_type, concrete_type.value_type))
-        return bindings
-      else:
-        return {}
-
-    def bind_type_variables(self, bindings):
-      bound_key_type = bind_type_variables(self.key_type, bindings)
-      bound_value_type = bind_type_variables(self.value_type, bindings)
-      if (bound_key_type, self.key_type) == (bound_value_type, self.value_type):
-        return self
-      else:
-        return Dict[bound_key_type, bound_value_type]
-
-  def __getitem__(self, type_params):
-    # Type param must be a (k, v) pair.
-    if not isinstance(type_params, tuple):
-      raise TypeError('Parameter to Dict type-hint must be a tuple of types: '
-                      'Dict[.., ..].')
-
-    if len(type_params) != 2:
-      raise TypeError(
-          'Length of parameters to a Dict type-hint must be exactly 2. Passed '
-          'parameters: %s, have a length of %s.' %
-          (type_params, len(type_params))
-      )
-
-    key_type, value_type = type_params
-
-    validate_composite_type_param(
-        key_type,
-        error_msg_prefix='Key-type parameter to a Dict hint'
-    )
-    validate_composite_type_param(
-        value_type,
-        error_msg_prefix='Value-type parameter to a Dict hint'
-    )
-
-    return self.DictConstraint(key_type, value_type)
-
-
-DictConstraint = DictHint.DictConstraint
-
-
-class SetHint(CompositeTypeHint):
-  """A Set type-hint.
-
-
-  Set[X] defines a type-hint for a set of homogeneous types. 'X' may be either a
-  built-in Python type or a another nested TypeConstraint.
-  """
-
-  class SetTypeConstraint(SequenceTypeConstraint):
-
-    def __init__(self, type_param):
-      super(SetHint.SetTypeConstraint, self).__init__(type_param, set)
-
-    def __repr__(self):
-      return 'Set[%s]' % _unified_repr(self.inner_type)
-
-  def __getitem__(self, type_param):
-    validate_composite_type_param(
-        type_param,
-        error_msg_prefix='Parameter to a Set hint'
-    )
-
-    return self.SetTypeConstraint(type_param)
-
-
-SetTypeConstraint = SetHint.SetTypeConstraint
-
-
-class IterableHint(CompositeTypeHint):
-  """An Iterable type-hint.
-
-  Iterable[X] defines a type-hint for an object implementing an '__iter__'
-  method which yields objects which are all of the same type.
-  """
-
-  class IterableTypeConstraint(SequenceTypeConstraint):
-
-    def __init__(self, iter_type):
-      super(IterableHint.IterableTypeConstraint, self).__init__(
-          iter_type, collections.Iterable)
-
-    def __repr__(self):
-      return 'Iterable[%s]' % _unified_repr(self.inner_type)
-
-    def _consistent_with_check_(self, sub):
-      if isinstance(sub, SequenceTypeConstraint):
-        return is_consistent_with(sub.inner_type, self.inner_type)
-      elif isinstance(sub, TupleConstraint):
-        if not sub.tuple_types:
-          # The empty tuple is consistent with Iterator[T] for any T.
-          return True
-        else:
-          # Each element in the hetrogenious tuple must be consistent with
-          # the iterator type.
-          # E.g. Tuple[A, B] < Iterable[C] if A < C and B < C.
-          return all(is_consistent_with(elem, self.inner_type)
-                     for elem in sub.tuple_types)
-      else:
-        return False
-
-  def __getitem__(self, type_param):
-    validate_composite_type_param(
-        type_param, error_msg_prefix='Parameter to an Iterable hint'
-    )
-
-    return self.IterableTypeConstraint(type_param)
-
-
-IterableTypeConstraint = IterableHint.IterableTypeConstraint
-
-
-class IteratorHint(CompositeTypeHint):
-  """An Iterator type-hint.
-
-  Iterator[X] defines a type-hint for an object implementing both '__iter__'
-  and a 'next' method which yields objects which are all of the same type. Type
-  checking a type-hint of this type is deferred in order to avoid depleting the
-  underlying lazily generated sequence. See decorators.interleave_type_check for
-  further information.
-  """
-
-  class IteratorTypeConstraint(TypeConstraint):
-
-    def __init__(self, t):
-      self.yielded_type = t
-
-    def __repr__(self):
-      return 'Iterator[%s]' % _unified_repr(self.yielded_type)
-
-    def _inner_types(self):
-      yield self.yielded_type
-
-    def _consistent_with_check_(self, sub):
-      return (isinstance(sub, self.__class__)
-              and is_consistent_with(sub.yielded_type, self.yielded_type))
-
-    def type_check(self, instance):
-      # Special case for lazy types, we only need to enforce the underlying
-      # type. This avoid having to compute the entirety of the generator/iter.
-      try:
-        check_constraint(self.yielded_type, instance)
-        return
-      except CompositeTypeHintError as e:
-        raise CompositeTypeHintError(
-            '%s hint type-constraint violated: %s' % (repr(self), str(e)))
-      except SimpleTypeHintError:
-        raise CompositeTypeHintError(
-            '%s hint type-constraint violated. Expected a iterator of type %s. '
-            'Instead received a iterator of type %s.'
-            % (repr(self), _unified_repr(self.yielded_type),
-               instance.__class__.__name__))
-
-  def __getitem__(self, type_param):
-    validate_composite_type_param(
-        type_param, error_msg_prefix='Parameter to an Iterator hint'
-    )
-
-    return self.IteratorTypeConstraint(type_param)
-
-
-IteratorTypeConstraint = IteratorHint.IteratorTypeConstraint
-
-
-class WindowedTypeConstraint(TypeConstraint):
-  """A type constraint for WindowedValue objects.
-
-  Mostly for internal use.
-
-  Attributes:
-    inner_type: The type which the element should be an instance of.
-  """
-  __metaclass__ = GetitemConstructor
-
-  def __init__(self, inner_type):
-    self.inner_type = inner_type
-
-  def __eq__(self, other):
-    return (isinstance(other, WindowedTypeConstraint)
-            and self.inner_type == other.inner_type)
-
-  def __hash__(self):
-    return hash(self.inner_type) ^ 13 * hash(type(self))
-
-  def _inner_types(self):
-    yield self.inner_type
-
-  def _consistent_with_check_(self, sub):
-    return (isinstance(sub, self.__class__)
-            and is_consistent_with(sub.inner_type, self.inner_type))
-
-  def type_check(self, instance):
-    from google.cloud.dataflow.transforms import window
-    if not isinstance(instance, window.WindowedValue):
-      raise CompositeTypeHintError(
-          "Window type-constraint violated. Valid object instance "
-          "must be of type 'WindowedValue'. Instead, an instance of '%s' "
-          "was received."
-          % (instance.__class__.__name__))
-
-    try:
-      check_constraint(self.inner_type, instance.value)
-    except (CompositeTypeHintError, SimpleTypeHintError) as e:
-      raise CompositeTypeHintError(
-          '%s hint type-constraint violated. The type of element in '
-          'is incorrect. Expected an instance of type %s, '
-          'instead received an instance of type %s.' %
-          (repr(self), _unified_repr(self.inner_type), elem.__class__.__name__))
-
-
-class GeneratorHint(IteratorHint):
-  pass
-
-
-# Create the actual instances for all defined type-hints above.
-Any = AnyTypeConstraint()
-Union = UnionHint()
-Optional = OptionalHint()
-Tuple = TupleHint()
-List = ListHint()
-KV = KVHint()
-Dict = DictHint()
-Set = SetHint()
-Iterable = IterableHint()
-Iterator = IteratorHint()
-Generator = GeneratorHint()
-WindowedValue = WindowedTypeConstraint
-
-
-_KNOWN_PRIMITIVE_TYPES = {
-    dict: Dict[Any, Any],
-    list: List[Any],
-    tuple: Tuple[Any, ...],
-    set: Set[Any],
-    # Using None for the NoneType is a common convention.
-    None: type(None),
-}
-
-
-def normalize(x):
-  if x in _KNOWN_PRIMITIVE_TYPES:
-    return _KNOWN_PRIMITIVE_TYPES[x]
-  else:
-    return x
-
-
-def is_consistent_with(sub, base):
-  """Returns whether the type a is consistent with b.
-
-  This is accordig to the terminology of PEP 483/484.  This relationship is
-  neither symmetric nor transitive, but a good mnemonic to keep in mind is that
-  is_consistent_with(a, b) is roughly equivalent to the issubclass(a, b)
-  relation, but also handles the special Any type as well as type
-  parameterization.
-  """
-  if sub == base:
-    # Common special case.
-    return True
-  if isinstance(sub, AnyTypeConstraint) or isinstance(base, AnyTypeConstraint):
-    return True
-  sub = normalize(sub)
-  base = normalize(base)
-  if isinstance(base, TypeConstraint):
-    return base._consistent_with_check_(sub)
-  elif isinstance(sub, TypeConstraint):
-    # Nothing but object lives above any type constraints.
-    return base == object
-  else:
-    return issubclass(sub, base)

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/b14dfadd/sdks/python/google/cloud/dataflow/typehints/typehints_test.py
----------------------------------------------------------------------
diff --git a/sdks/python/google/cloud/dataflow/typehints/typehints_test.py b/sdks/python/google/cloud/dataflow/typehints/typehints_test.py
deleted file mode 100644
index 83c61f2..0000000
--- a/sdks/python/google/cloud/dataflow/typehints/typehints_test.py
+++ /dev/null
@@ -1,1053 +0,0 @@
-# Copyright 2016 Google Inc. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""Unit tests for the type-hint objects and decorators."""
-import functools
-import inspect
-import unittest
-
-
-import google.cloud.dataflow.typehints as typehints
-from google.cloud.dataflow.typehints import Any
-from google.cloud.dataflow.typehints import is_consistent_with
-from google.cloud.dataflow.typehints import Tuple
-from google.cloud.dataflow.typehints import TypeCheckError
-from google.cloud.dataflow.typehints import Union
-from google.cloud.dataflow.typehints import with_input_types
-from google.cloud.dataflow.typehints import with_output_types
-from google.cloud.dataflow.typehints.decorators import _check_instance_type
-from google.cloud.dataflow.typehints.decorators import _interleave_type_check
-from google.cloud.dataflow.typehints.decorators import _positional_arg_hints
-from google.cloud.dataflow.typehints.decorators import get_type_hints
-from google.cloud.dataflow.typehints.decorators import getcallargs_forhints
-
-
-def check_or_interleave(hint, value, var):
-  if hint is None:
-    return value
-  elif isinstance(hint, typehints.IteratorHint.IteratorTypeConstraint):
-    return _interleave_type_check(hint, var)(value)
-  else:
-    _check_instance_type(hint, value, var)
-    return value
-
-def check_type_hints(f):
-  @functools.wraps(f)
-  def wrapper(*args, **kwargs):
-    hints = get_type_hints(f)
-    if hints.input_types:
-      input_hints = getcallargs_forhints(
-          f, *hints.input_types[0], **hints.input_types[1])
-      inputs = inspect.getcallargs(f, *args, **kwargs)
-      for var, hint in input_hints.items():
-        value = inputs[var]
-        new_value = check_or_interleave(hint, value, var)
-        if new_value is not value:
-          if var in kwargs:
-            kwargs[var] = new_value
-          else:
-            args = list(args)
-            for ix, pvar in enumerate(inspect.getargspec(f).args):
-              if pvar == var:
-                args[ix] = new_value
-                break
-            else:
-              raise NotImplementedError('Iterable in nested argument %s' % var)
-    res = f(*args, **kwargs)
-    return check_or_interleave(hints.simple_output_type('typecheck'), res, None)
-  return wrapper
-
-
-class DummyTestClass1(object):
-  pass
-
-
-class DummyTestClass2(object):
-  pass
-
-
-class SuperClass(object):
-  pass
-
-
-class SubClass(SuperClass):
-  pass
-
-
-class TypeHintTestCase(unittest.TestCase):
-
-  def assertCompatible(self, base, sub):  # pylint: disable=invalid-name
-    self.assertTrue(
-        is_consistent_with(sub, base),
-        '%s is not consistent with %s' % (sub, base))
-
-  def assertNotCompatible(self, base, sub):  # pylint: disable=invalid-name
-    self.assertFalse(
-        is_consistent_with(sub, base),
-        '%s is consistent with %s' % (sub, base))
-
-
-class AnyTypeConstraintTestCase(TypeHintTestCase):
-
-  def test_any_compatibility(self):
-    self.assertCompatible(typehints.Any, typehints.List[int])
-    self.assertCompatible(typehints.Any, DummyTestClass1)
-    self.assertCompatible(typehints.Union[int, bool], typehints.Any)
-    self.assertCompatible(typehints.Optional[int], typehints.Any)
-    self.assertCompatible(typehints.Tuple[int], typehints.Any)
-    self.assertCompatible(typehints.KV[int, str], typehints.Any)
-    self.assertCompatible(typehints.Dict[int, bool], typehints.Any)
-    self.assertCompatible(typehints.Set[int], typehints.Any)
-    self.assertCompatible(typehints.Iterable[int], typehints.Any)
-    self.assertCompatible(typehints.Iterator[int], typehints.Any)
-    self.assertCompatible(typehints.Generator[int], typehints.Any)
-    self.assertCompatible(object, typehints.Any)
-    self.assertCompatible(typehints.Any, object)
-
-  def test_repr(self):
-    self.assertEqual('Any', repr(typehints.Any))
-
-  def test_type_check(self):
-    # This test passes if the type_check call does not raise any exception.
-    typehints.Any.type_check(1)
-    typehints.Any.type_check([1, 2, 3])
-    typehints.Any.type_check(DummyTestClass1())
-
-
-class UnionHintTestCase(TypeHintTestCase):
-
-  def test_getitem_must_be_valid_type_param_cant_be_object_instance(self):
-    with self.assertRaises(TypeError) as e:
-      typehints.Union[5]
-    self.assertEqual('Cannot create Union without a sequence of types.',
-                     e.exception.message)
-
-  def test_getitem_must_be_valid_type_param(self):
-    t = [2, 3]
-    with self.assertRaises(TypeError) as e:
-      typehints.Union[t]
-    self.assertEqual('All parameters to a Union hint must be a non-sequence, '
-                     'a type, or a TypeConstraint. 2 is an instance of int.',
-                     e.exception.message)
-
-  def test_getitem_duplicates_ignored(self):
-    # Types should be de-duplicated.
-    hint = typehints.Union[int, int, str]
-    self.assertEqual(len(hint.union_types), 2)
-
-  def test_getitem_nested_unions_flattened(self):
-    # The two Union's should be merged into 1.
-    hint = typehints.Union[typehints.Union[int, str],
-                           typehints.Union[float, bool]]
-    self.assertTrue(len(hint.union_types) == 4)
-    self.assertTrue(all(t in hint.union_types for t in (int, str, float, bool)))
-
-  def test_union_hint_compatibility(self):
-    self.assertCompatible(typehints.Union[int, float], int)
-    self.assertCompatible(typehints.Union[int, str], typehints.Union[str, int])
-    self.assertCompatible(typehints.Union[int, float, str],
-                          typehints.Union[str, int])
-
-    self.assertCompatible(
-        typehints.Union[DummyTestClass1, str],
-        typehints.Union[DummyTestClass1, str])
-
-    self.assertCompatible(typehints.Union[int, str],
-                          typehints.Union[str, typehints.Union[int, str]])
-
-    self.assertNotCompatible(typehints.Union[float, bool],
-                             typehints.Union[int, bool])
-    self.assertNotCompatible(typehints.Union[bool, str],
-                             typehints.Union[float, bool, int])
-
-  def test_nested_compatibility(self):
-    self.assertCompatible(Union[int, Tuple[Any, int]], Tuple[int, int])
-    self.assertCompatible(Union[int, Tuple[Any, Any]],
-                          Union[Tuple[int, Any], Tuple[Any, int]])
-    self.assertCompatible(Union[int, SuperClass], SubClass)
-    self.assertCompatible(Union[int, float, SuperClass], Union[int, SubClass])
-
-    self.assertNotCompatible(Union[int, SubClass], SuperClass)
-    self.assertNotCompatible(Union[int, float, SubClass],
-                             Union[int, SuperClass])
-    self.assertNotCompatible(Union[int, SuperClass],
-                             Union[int, float, SubClass])
-
-  def test_union_hint_repr(self):
-    hint = typehints.Union[DummyTestClass1, str]
-    self.assertIn(
-        str(hint),
-        # Uses frozen set internally, so order not guaranteed.
-        ['Union[str, DummyTestClass1]',
-         'Union[DummyTestClass1, str]']
-    )
-
-  def test_union_hint_enforcement_composite_type_in_union(self):
-    o = DummyTestClass1()
-    hint = typehints.Union[int, DummyTestClass1]
-
-    self.assertIsNone(hint.type_check(4))
-    self.assertIsNone(hint.type_check(o))
-
-  def test_union_hint_enforcement_part_of_union(self):
-    hint = typehints.Union[int, str]
-    self.assertIsNone(hint.type_check(5))
-    self.assertIsNone(hint.type_check('test'))
-
-  def test_union_hint_enforcement_not_part_of_union(self):
-    hint = typehints.Union[int, float]
-    with self.assertRaises(TypeError) as e:
-      hint.type_check('test')
-
-    self.assertEqual("Union[float, int] type-constraint violated. Expected an "
-                     "instance of one of: ('float', 'int'), received str "
-                     "instead.",
-                     e.exception.message)
-
-
-class OptionalHintTestCase(TypeHintTestCase):
-
-  def test_getitem_sequence_not_allowed(self):
-    with self.assertRaises(TypeError) as e:
-      typehints.Optional[int, str]
-    self.assertTrue(e.exception.message.startswith(
-        'An Option type-hint only accepts a single type parameter.'))
-
-  def test_getitem_proxy_to_union(self):
-    hint = typehints.Optional[int]
-    self.assertTrue(isinstance(hint, typehints.UnionHint.UnionConstraint))
-
-
-class TupleHintTestCase(TypeHintTestCase):
-
-  def test_getitem_invalid_ellipsis_type_param(self):
-    error_msg = ('Ellipsis can only be used to type-hint an arbitrary length '
-                 'tuple of containing a single type: Tuple[A, ...].')
-
-    with self.assertRaises(TypeError) as e:
-      typehints.Tuple[int, int, ...]
-    self.assertEqual(error_msg, e.exception.message)
-
-    with self.assertRaises(TypeError) as e:
-      typehints.Tuple[...]
-    self.assertEqual(error_msg, e.exception.message)
-
-  def test_getitem_params_must_be_type_or_constraint(self):
-    expected_error_prefix = 'All parameters to a Tuple hint must be'
-    with self.assertRaises(TypeError) as e:
-      typehints.Tuple[5, [1, 3]]
-    self.assertTrue(e.exception.message.startswith(expected_error_prefix))
-
-    with self.assertRaises(TypeError) as e:
-      typehints.Tuple[list, dict]
-    self.assertTrue(e.exception.message.startswith(expected_error_prefix))
-
-  def test_compatibility_arbitrary_length(self):
-    self.assertNotCompatible(
-        typehints.Tuple[int, int], typehints.Tuple[int, ...])
-    self.assertCompatible(
-        typehints.Tuple[int, ...], typehints.Tuple[int, int])
-    self.assertCompatible(
-        typehints.Tuple[Any, ...], typehints.Tuple[int, float])
-    self.assertCompatible(
-        typehints.Tuple[SuperClass, ...], typehints.Tuple[SubClass, SuperClass])
-
-    self.assertCompatible(typehints.Iterable[int], typehints.Tuple[int, ...])
-    self.assertCompatible(typehints.Iterable[SuperClass],
-                          typehints.Tuple[SubClass, ...])
-
-  def test_compatibility(self):
-    self.assertCompatible(typehints.Tuple[int, str], typehints.Tuple[int, str])
-    self.assertCompatible(typehints.Tuple[int, Any], typehints.Tuple[int, str])
-    self.assertCompatible(typehints.Tuple[int, str], typehints.Tuple[int, Any])
-    self.assertCompatible(typehints.Tuple[typehints.Union[int, str], bool],
-                          typehints.Tuple[typehints.Union[int, str], bool])
-    self.assertCompatible(typehints.Tuple[typehints.Union[str, int], int],
-                          typehints.Tuple[typehints.Union[int, str], int])
-    self.assertCompatible(typehints.Tuple[SuperClass, int],
-                          typehints.Tuple[SubClass, int])
-
-    self.assertNotCompatible(typehints.Tuple[int, int],
-                             typehints.Tuple[int, int, int])
-
-  def test_raw_tuple(self):
-    self.assertCompatible(tuple, typehints.Tuple[int])
-    self.assertCompatible(tuple, typehints.Tuple[int, float])
-    self.assertCompatible(tuple, typehints.Tuple[int, ...])
-
-  def test_repr(self):
-    hint = typehints.Tuple[int, str, float]
-    self.assertEqual('Tuple[int, str, float]', str(hint))
-
-    hint = typehints.Tuple[DummyTestClass1, DummyTestClass2]
-    self.assertEqual('Tuple[DummyTestClass1, DummyTestClass2]',
-                     str(hint))
-
-    hint = typehints.Tuple[float, ...]
-    self.assertEqual('Tuple[float, ...]', str(hint))
-
-  def test_type_check_must_be_tuple(self):
-    hint = typehints.Tuple[int, str]
-    expected_error_prefix = 'Tuple type constraint violated. Valid object'
-    invalid_instances = ([1, 2, 3], {4: 'f'}, 9, 'test', None)
-    for t in invalid_instances:
-      with self.assertRaises(TypeError) as e:
-        hint.type_check(t)
-      self.assertTrue(e.exception.message.startswith(expected_error_prefix))
-
-  def test_type_check_must_have_same_arity(self):
-    # A 2-tuple of ints.
-    hint = typehints.Tuple[int, int]
-    t = (1, 2, 3)
-
-    with self.assertRaises(TypeError) as e:
-      hint.type_check(t)
-    self.assertEqual('Passed object instance is of the proper type, but '
-                     'differs in length from the hinted type. Expected a '
-                     'tuple of length 2, received a tuple of length 3.',
-                     e.exception.message)
-
-  def test_type_check_invalid_simple_types(self):
-    hint = typehints.Tuple[str, bool]
-    with self.assertRaises(TypeError) as e:
-      hint.type_check((4, False))
-    self.assertEqual('Tuple[str, bool] hint type-constraint violated. The '
-                     'type of element #0 in the passed tuple is incorrect.'
-                     ' Expected an instance of type str, instead received '
-                     'an instance of type int.',
-                     e.exception.message)
-
-  def test_type_check_invalid_composite_type(self):
-    hint = typehints.Tuple[DummyTestClass1, DummyTestClass2]
-    t = (DummyTestClass2(), DummyTestClass1())
-    with self.assertRaises(TypeError) as e:
-      hint.type_check(t)
-
-    self.assertEqual('Tuple[DummyTestClass1, DummyTestClass2] hint '
-                     'type-constraint violated. The type of element #0 in the '
-                     'passed tuple is incorrect. Expected an instance of type '
-                     'DummyTestClass1, instead received an instance of type '
-                     'DummyTestClass2.',
-                     e.exception.message)
-
-  def test_type_check_valid_simple_types(self):
-    hint = typehints.Tuple[float, bool]
-    self.assertIsNone(hint.type_check((4.3, True)))
-
-    hint = typehints.Tuple[int]
-    self.assertIsNone(hint.type_check((1,)))
-
-  def test_type_check_valid_composite_types(self):
-    hint = typehints.Tuple[typehints.Tuple[int, str],
-                           typehints.Tuple[int, bool]]
-    self.assertIsNone(hint.type_check(
-        ((4, 'test'), (4, True))
-    ))
-
-  def test_type_check_valid_simple_type_arbitrary_length(self):
-    hint = typehints.Tuple[int, ...]
-    t = (1, 2, 3, 4)
-    self.assertIsNone(hint.type_check(t))
-
-  def test_type_check_valid_composite_type_arbitrary_length(self):
-    hint = typehints.Tuple[typehints.List[str], ...]
-    t = (['h', 'e'], ['l', 'l'], ['o'])
-    self.assertIsNone(hint.type_check(t))
-
-  def test_type_check_invalid_simple_type_arbitrary_length(self):
-    hint = typehints.Tuple[str, ...]
-
-    t = ('t', 'e', 5, 't')
-    with self.assertRaises(TypeError) as e:
-      hint.type_check(t)
-
-    self.assertEqual('Tuple[str, ...] hint type-constraint violated. The type '
-                     'of element #2 in the passed tuple is incorrect. Expected '
-                     'an instance of type str, instead received an instance of '
-                     'type int.',
-                     e.exception.message)
-
-  def test_type_check_invalid_composite_type_arbitrary_length(self):
-    hint = typehints.Tuple[typehints.List[int], ...]
-
-    t = ([1, 2], 'e', 's', 't')
-    with self.assertRaises(TypeError) as e:
-      hint.type_check(t)
-
-    self.assertEqual("Tuple[List[int], ...] hint type-constraint violated. The "
-                     "type of element #1 in the passed tuple is incorrect: "
-                     "List type-constraint violated. Valid object instance "
-                     "must be of type 'list'. Instead, an instance of 'str' "
-                     "was received.",
-                     e.exception.message)
-
-
-class ListHintTestCase(TypeHintTestCase):
-
-  def test_getitem_invalid_composite_type_param(self):
-    with self.assertRaises(TypeError) as e:
-      typehints.List[4]
-
-  def test_list_constraint_compatibility(self):
-    hint1 = typehints.List[typehints.Tuple[int, str]]
-    hint2 = typehints.List[typehints.Tuple[float, bool]]
-
-    self.assertCompatible(hint1, hint1)
-    self.assertNotCompatible(hint1, hint2)
-
-    self.assertCompatible(typehints.List[SuperClass], typehints.List[SubClass])
-
-  def test_list_repr(self):
-    hint = (
-        typehints.List[typehints.Tuple[DummyTestClass1, DummyTestClass2]]
-    )
-    self.assertEqual('List[Tuple[DummyTestClass1, DummyTestClass2]]',
-                     repr(hint))
-
-  def test_enforce_list_type_constraint_valid_simple_type(self):
-    hint = typehints.List[int]
-    self.assertIsNone(hint.type_check([1, 2, 3]))
-
-  def test_enforce_list_type_constraint_valid_composite_type(self):
-    hint = typehints.List[DummyTestClass1]
-    l = [DummyTestClass1(), DummyTestClass1()]
-    self.assertIsNone(hint.type_check(l))
-
-  def test_enforce_list_type_constraint_invalid_simple_type(self):
-    hint = typehints.List[int]
-    l = ['f', 'd', 'm']
-    with self.assertRaises(TypeError) as e:
-      hint.type_check(l)
-    self.assertEqual('List[int] hint type-constraint violated. The type of '
-                     'element #0 in the passed list is incorrect. Expected an '
-                     'instance of type int, instead received an instance of '
-                     'type str.',
-                     e.exception.message)
-
-  def test_enforce_list_type_constraint_invalid_composite_type(self):
-    hint = typehints.List[typehints.Tuple[int, int]]
-    l = [('f', 1), ('m', 5)]
-    with self.assertRaises(TypeError) as e:
-      hint.type_check(l)
-
-    self.assertEqual('List[Tuple[int, int]] hint type-constraint violated.'
-                     ' The type of element #0 in the passed list is '
-                     'incorrect: Tuple[int, int] hint type-constraint '
-                     'violated. The type of element #0 in the passed tuple'
-                     ' is incorrect. Expected an instance of type int, '
-                     'instead received an instance of type str.',
-                     e.exception.message)
-
-
-class KVHintTestCase(TypeHintTestCase):
-
-  def test_getitem_param_must_be_tuple(self):
-    with self.assertRaises(TypeError) as e:
-      typehints.KV[4]
-
-    self.assertEqual('Parameter to KV type-hint must be a tuple of types: '
-                     'KV[.., ..].',
-                     e.exception.message)
-
-  def test_getitem_param_must_have_length_2(self):
-    with self.assertRaises(TypeError) as e:
-      typehints.KV[int, str, bool]
-
-    self.assertEqual("Length of parameters to a KV type-hint must be "
-                     "exactly 2. Passed parameters: (<type 'int'>, <type "
-                     "'str'>, <type 'bool'>), have a length of 3.",
-                     e.exception.message)
-
-  def test_getitem_proxy_to_tuple(self):
-    hint = typehints.KV[int, str]
-    self.assertTrue(isinstance(hint, typehints.Tuple.TupleConstraint))
-
-  def test_enforce_kv_type_constraint(self):
-    hint = typehints.KV[str, typehints.Tuple[int, int, int]]
-    t = ('test', (1, 2, 3))
-    self.assertIsNone(hint.type_check(t))
-
-
-class DictHintTestCase(TypeHintTestCase):
-
-  def test_getitem_param_must_be_tuple(self):
-    with self.assertRaises(TypeError) as e:
-      typehints.Dict[4]
-
-    self.assertEqual('Parameter to Dict type-hint must be a tuple of '
-                     'types: Dict[.., ..].',
-                     e.exception.message)
-
-  def test_getitem_param_must_have_length_2(self):
-    with self.assertRaises(TypeError) as e:
-      typehints.Dict[float, int, bool]
-
-    self.assertEqual("Length of parameters to a Dict type-hint must be "
-                     "exactly 2. Passed parameters: (<type 'float'>, <type "
-                     "'int'>, <type 'bool'>), have a length of 3.",
-                     e.exception.message)
-
-  def test_key_type_must_be_valid_composite_param(self):
-    with self.assertRaises(TypeError) as e:
-      typehints.Dict[list, int]
-
-  def test_value_type_must_be_valid_composite_param(self):
-    with self.assertRaises(TypeError) as e:
-      typehints.Dict[str, 5]
-
-  def test_compatibility(self):
-    hint1 = typehints.Dict[int, str]
-    hint2 = typehints.Dict[bool, int]
-    hint3 = typehints.Dict[int, typehints.List[typehints.Tuple[str, str, str]]]
-
-    self.assertCompatible(hint1, hint1)
-    self.assertCompatible(hint3, hint3)
-    self.assertNotCompatible(hint3, 4)
-    self.assertNotCompatible(hint2, hint1)
-
-  def test_repr(self):
-    hint3 = typehints.Dict[int, typehints.List[typehints.Tuple[str, str, str]]]
-    self.assertEqual('Dict[int, List[Tuple[str, str, str]]]', repr(hint3))
-
-  def test_type_checks_not_dict(self):
-    hint = typehints.Dict[int, str]
-    l = [1, 2]
-    with self.assertRaises(TypeError) as e:
-      hint.type_check(l)
-    self.assertEqual('Dict type-constraint violated. All passed instances '
-                     'must be of type dict. [1, 2] is of type list.',
-                     e.exception.message)
-
-  def test_type_check_invalid_key_type(self):
-    hint = typehints.Dict[typehints.Tuple[int, int, int],
-                          typehints.List[str]
-                         ]
-    d = {(1, 2): ['m', '1', '2', '3']}
-    with self.assertRaises((TypeError, TypeError)) as e:
-      hint.type_check(d)
-    self.assertEqual('Dict[Tuple[int, int, int], List[str]] hint key-type '
-                     'constraint violated. All keys should be of type '
-                     'Tuple[int, int, int]. Instead: Passed object '
-                     'instance is of the proper type, but differs in '
-                     'length from the hinted type. Expected a tuple of '
-                     'length 3, received a tuple of length 2.',
-                     e.exception.message)
-
-  def test_type_check_invalid_value_type(self):
-    hint = typehints.Dict[str, typehints.Dict[int, str]]
-    d = {'f': [1, 2, 3]}
-    with self.assertRaises(TypeError) as e:
-      hint.type_check(d)
-    self.assertEqual('Dict[str, Dict[int, str]] hint value-type constraint'
-                     ' violated. All values should be of type '
-                     'Dict[int, str]. Instead: Dict type-constraint '
-                     'violated. All passed instances must be of type dict.'
-                     ' [1, 2, 3] is of type list.',
-                     e.exception.message)
-
-  def test_type_check_valid_simple_type(self):
-    hint = typehints.Dict[int, str]
-    d = {4: 'f', 9: 'k'}
-    self.assertIsNone(hint.type_check(d))
-
-  def test_type_check_valid_composite_type(self):
-    hint = typehints.Dict[typehints.Tuple[str, str], typehints.List[int]]
-    d = {('f', 'k'): [1, 2, 3], ('m', 'r'): [4, 6, 9]}
-    self.assertIsNone(hint.type_check(d))
-
-  def test_match_type_variables(self):
-    S = typehints.TypeVariable('S')  # pylint: disable=invalid-name
-    T = typehints.TypeVariable('T')  # pylint: disable=invalid-name
-    hint = typehints.Dict[S, T]
-    self.assertEqual({S: int, T: str},
-                     hint.match_type_variables(typehints.Dict[int, str]))
-
-
-class SetHintTestCase(TypeHintTestCase):
-
-  def test_getitem_invalid_composite_type_param(self):
-    with self.assertRaises(TypeError) as e:
-      typehints.Set[list]
-    self.assertEqual("Parameter to a Set hint must be a non-sequence, a "
-                     "type, or a TypeConstraint. <type 'list'> is an "
-                     "instance of type.",
-                     e.exception.message)
-
-  def test_compatibility(self):
-    hint1 = typehints.Set[typehints.List[str]]
-    hint2 = typehints.Set[typehints.Tuple[int, int]]
-
-    self.assertCompatible(hint1, hint1)
-    self.assertNotCompatible(hint2, hint1)
-
-  def test_repr(self):
-    hint = typehints.Set[typehints.List[bool]]
-    self.assertEqual('Set[List[bool]]', repr(hint))
-
-  def test_type_check_must_be_set(self):
-    hint = typehints.Set[str]
-    with self.assertRaises(TypeError) as e:
-      hint.type_check(4)
-
-    self.assertEqual("Set type-constraint violated. Valid object instance "
-                     "must be of type 'set'. Instead, an instance of 'int'"
-                     " was received.",
-                     e.exception.message)
-
-  def test_type_check_invalid_elem_type(self):
-    hint = typehints.Set[float]
-    with self.assertRaises(TypeError):
-      hint.type_check('f')
-
-  def test_type_check_valid_elem_simple_type(self):
-    hint = typehints.Set[str]
-    s = set(['f', 'm', 'k'])
-    self.assertIsNone(hint.type_check(s))
-
-  def test_type_check_valid_elem_composite_type(self):
-    hint = typehints.Set[typehints.Union[int, str]]
-    s = set([9, 'm', 'k'])
-    self.assertIsNone(hint.type_check(s))
-
-
-class IterableHintTestCase(TypeHintTestCase):
-
-  def test_getitem_invalid_composite_type_param(self):
-    with self.assertRaises(TypeError) as e:
-      typehints.Iterable[5]
-    self.assertEqual('Parameter to an Iterable hint must be a '
-                     'non-sequence, a type, or a TypeConstraint. 5 is '
-                     'an instance of int.',
-                     e.exception.message)
-
-  def test_compatibility(self):
-    self.assertCompatible(typehints.Iterable[int], typehints.List[int])
-    self.assertCompatible(typehints.Iterable[int], typehints.Set[int])
-    self.assertCompatible(typehints.Iterable[typehints.Any],
-                          typehints.List[typehints.Tuple[int, bool]])
-
-    self.assertCompatible(typehints.Iterable[int], typehints.Iterable[int])
-    self.assertCompatible(typehints.Iterable[typehints.Union[int, str]],
-                          typehints.Iterable[typehints.Union[int, str]])
-    self.assertNotCompatible(typehints.Iterable[str], typehints.Iterable[bool])
-
-    self.assertCompatible(typehints.Iterable[int], typehints.List[int])
-    self.assertCompatible(typehints.Iterable[int], typehints.Set[int])
-    self.assertCompatible(typehints.Iterable[typehints.Any],
-                          typehints.List[typehints.Tuple[int, bool]])
-
-  def test_tuple_compatibility(self):
-    self.assertCompatible(typehints.Iterable[int], typehints.Tuple[int, ...])
-    self.assertCompatible(typehints.Iterable[SuperClass],
-                          typehints.Tuple[SubClass, ...])
-    self.assertCompatible(typehints.Iterable[int], typehints.Tuple[int, int])
-    self.assertCompatible(typehints.Iterable[Any], typehints.Tuple[int, float])
-    self.assertCompatible(typehints.Iterable[typehints.Union[int, float]],
-                          typehints.Tuple[int, ...])
-    self.assertCompatible(typehints.Iterable[typehints.Union[int, float]],
-                          typehints.Tuple[int, float])
-    self.assertCompatible(typehints.Iterable[typehints.Union[int, float]],
-                          typehints.Tuple[int, float, int])
-
-  def test_repr(self):
-    hint = typehints.Iterable[typehints.Set[str]]
-    self.assertEqual('Iterable[Set[str]]', repr(hint))
-
-  def test_type_check_must_be_iterable(self):
-    with self.assertRaises(TypeError) as e:
-      hint = typehints.Iterable[int]
-      hint.type_check(5)
-
-    self.assertEqual("Iterable type-constraint violated. Valid object "
-                     "instance must be of type 'iterable'. Instead, an "
-                     "instance of 'int' was received.",
-                     e.exception.message)
-
-  def test_type_check_violation_invalid_simple_type(self):
-    hint = typehints.Iterable[float]
-    l = set([1, 2, 3, 4])
-    with self.assertRaises(TypeError):
-      hint.type_check(l)
-
-  def test_type_check_violation_valid_simple_type(self):
-    hint = typehints.Iterable[str]
-    l = ('t', 'e', 's', 't')
-    self.assertIsNone(hint.type_check(l))
-
-  def test_type_check_violation_invalid_composite_type(self):
-    hint = typehints.Iterable[typehints.List[int]]
-    l = ([['t', 'e'], ['s', 't']])
-    with self.assertRaises(TypeError) as e:
-      hint.type_check(l)
-
-  def test_type_check_violation_valid_composite_type(self):
-    hint = typehints.Iterable[typehints.List[int]]
-    l = ([[1, 2], [3, 4, 5]])
-    self.assertIsNone(hint.type_check(l))
-
-
-class TestGeneratorWrapper(TypeHintTestCase):
-
-  def test_functions_as_regular_generator(self):
-    def count(n):
-      for i in range(n):
-        yield i
-
-    l = []
-    interleave_func = lambda x: l.append(x)
-    wrapped_gen = typehints.GeneratorWrapper(count(4), interleave_func)
-
-    # Should function as a normal generator.
-    self.assertEqual(0, next(wrapped_gen))
-    self.assertEqual((1, 2, 3), tuple(wrapped_gen))
-
-    # Interleave function should have been called each time.
-    self.assertEqual([0, 1, 2, 3], l)
-
-
-class GeneratorHintTestCase(TypeHintTestCase):
-
-  def test_repr(self):
-    hint = typehints.Iterator[typehints.Set[str]]
-    self.assertEqual('Iterator[Set[str]]', repr(hint))
-
-  def test_compatibility(self):
-    self.assertCompatible(typehints.Iterator[int], typehints.Iterator[int])
-    self.assertNotCompatible(typehints.Iterator[str], typehints.Iterator[float])
-
-  def test_generator_return_hint_invalid_yield_type(self):
-    @check_type_hints
-    @with_output_types(typehints.Iterator[int])
-    def all_upper(s):
-      for e in s:
-        yield e.upper()
-
-    with self.assertRaises(TypeCheckError) as e:
-      next(all_upper('hello'))
-
-    self.assertEqual('Type-hint for return type violated: Iterator[int] '
-                     'hint type-constraint violated. Expected a iterator '
-                     'of type int. Instead received a iterator of type '
-                     'str.',
-                     e.exception.message)
-
-  def test_generator_argument_hint_invalid_yield_type(self):
-    def wrong_yield_gen():
-      for e in ['a', 'b']:
-        yield e
-
-    @check_type_hints
-    @with_input_types(a=typehints.Iterator[int])
-    def increment(a):
-      return [e + 1 for e in a]
-
-    with self.assertRaises(TypeCheckError) as e:
-      increment(wrong_yield_gen())
-
-    self.assertEqual("Type-hint for argument: 'a' violated: Iterator[int] "
-                     "hint type-constraint violated. Expected a iterator "
-                     "of type int. Instead received a iterator of type "
-                     "str.",
-                     e.exception.message)
-
-
-class TakesDecoratorTestCase(TypeHintTestCase):
-
-  def test_must_be_primitive_type_or_constraint(self):
-    with self.assertRaises(TypeError) as e:
-      t = [1, 2]
-      @with_input_types(a=t)
-      def foo(a):
-        pass
-
-    self.assertEqual('All type hint arguments must be a non-sequence, a '
-                     'type, or a TypeConstraint. [1, 2] is an instance of '
-                     'list.',
-                     e.exception.message)
-
-    with self.assertRaises(TypeError) as e:
-      t = 5
-      @check_type_hints
-      @with_input_types(a=t)
-      def foo(a):
-        pass
-
-    self.assertEqual('All type hint arguments must be a non-sequence, a type, '
-                     'or a TypeConstraint. 5 is an instance of int.',
-                     e.exception.message)
-
-  def test_basic_type_assertion(self):
-    @check_type_hints
-    @with_input_types(a=int)
-    def foo(a):
-      return a + 1
-
-    with self.assertRaises(TypeCheckError) as e:
-      m = 'a'
-      foo(m)
-    self.assertEqual("Type-hint for argument: 'a' violated. Expected an "
-                     "instance of <type 'int'>, instead found an "
-                     "instance of <type 'str'>.",
-                     e.exception.message)
-
-  def test_composite_type_assertion(self):
-    @check_type_hints
-    @with_input_types(a=typehints.List[int])
-    def foo(a):
-      a.append(1)
-      return a
-
-    with self.assertRaises(TypeCheckError) as e:
-      m = ['f', 'f']
-      foo(m)
-      self.assertEqual("Type-hint for argument: 'a' violated: List[int] hint "
-                       "type-constraint violated. The type of element #0 in "
-                       "the passed list is incorrect. Expected an instance of "
-                       "type int, instead received an instance of type str.",
-                       e.exception.message)
-
-  def test_valid_simple_type_arguments(self):
-    @with_input_types(a=str)
-    def upper(a):
-      return a.upper()
-
-    # Type constraints should pass, and function will be evaluated as normal.
-    self.assertEqual('M', upper('m'))
-
-  def test_any_argument_type_hint(self):
-    @check_type_hints
-    @with_input_types(a=typehints.Any)
-    def foo(a):
-      return 4
-
-    self.assertEqual(4, foo('m'))
-
-  def test_valid_mix_positional_and_keyword_arguments(self):
-    @check_type_hints
-    @with_input_types(typehints.List[int], elem=typehints.List[int])
-    def combine(container, elem):
-      return container + elem
-
-    self.assertEqual([1, 2, 3], combine([1, 2], [3]))
-
-  def test_invalid_only_positional_arguments(self):
-    @check_type_hints
-    @with_input_types(int, int)
-    def sub(a, b):
-      return a - b
-
-    with self.assertRaises(TypeCheckError) as e:
-      sub(1, 'two')
-
-    self.assertEqual("Type-hint for argument: 'b' violated. Expected an "
-                     "instance of <type 'int'>, instead found an instance "
-                     "of <type 'str'>.",
-                     e.exception.message)
-
-  def test_valid_only_positional_arguments(self):
-    @with_input_types(int, int)
-    def add(a, b):
-      return a + b
-
-    self.assertEqual(3, add(1, 2))
-
-
-class ReturnsDecoratorTestCase(TypeHintTestCase):
-
-  def test_no_kwargs_accepted(self):
-    with self.assertRaises(ValueError):
-      @with_output_types(m=int)
-      def foo():
-        return 5
-
-  def test_must_be_primitive_type_or_type_constraint(self):
-    with self.assertRaises(TypeError):
-      @with_output_types(5)
-      def foo():
-        pass
-
-    with self.assertRaises(TypeError):
-      @with_output_types([1, 2])
-      def foo():
-        pass
-
-  def test_must_be_single_return_type(self):
-    with self.assertRaises(ValueError):
-      @with_output_types(int, str)
-      def foo():
-        return 4, 'f'
-
-  def test_type_check_violation(self):
-    @check_type_hints
-    @with_output_types(int)
-    def foo(a):
-      return 'test'
-    with self.assertRaises(TypeCheckError) as e:
-      foo(4)
-
-    self.assertEqual("Type-hint for return type violated. Expected an "
-                     "instance of <type 'int'>, instead found an instance "
-                     "of <type 'str'>.",
-                     e.exception.message)
-
-  def test_type_check_simple_type(self):
-    @with_output_types(str)
-    def upper(a):
-      return a.upper()
-    self.assertEqual('TEST', upper('test'))
-
-  def test_type_check_composite_type(self):
-    @with_output_types(typehints.List[typehints.Tuple[int, int]])
-    def bar():
-      return [(i, i+1) for i in range(5)]
-
-    self.assertEqual([(0, 1), (1, 2), (2, 3), (3, 4), (4, 5)], bar())
-
-  def test_any_return_type_hint(self):
-    @with_output_types(typehints.Any)
-    def bar():
-      return 'foo'
-
-    self.assertEqual('foo', bar())
-
-
-class CombinedReturnsAndTakesTestCase(TypeHintTestCase):
-
-  def test_enable_and_disable_type_checking_takes(self):
-    @with_input_types(a=int)
-    def int_to_str(a):
-      return str(a)
-
-    # The function call below violates the argument type-hint above, but won't
-    # result in an exception since run-time type-checking was disabled above.
-    self.assertEqual('a', int_to_str('a'))
-
-    # Must re-define since the conditional is in the (maybe)wrapper.
-    @check_type_hints
-    @with_input_types(a=int)
-    def int_to_str(a):
-      return str(a)
-
-    # With run-time type checking enabled once again the same call-atttempt
-    # should result in a TypeCheckError.
-    with self.assertRaises(TypeCheckError):
-      int_to_str('a')
-
-  def test_enable_and_disable_type_checking_returns(self):
-    @with_output_types(str)
-    def int_to_str(a):
-      return a
-
-    # The return value of the function above violates the return-type
-    # type-hint above, but won't result in an exception since run-time
-    # type-checking was disabled above.
-    self.assertEqual(9, int_to_str(9))
-
-    # Must re-define since the conditional is in the (maybe)wrapper.
-    @check_type_hints
-    @with_output_types(str)
-    def int_to_str(a):
-      return a
-
-    # With type-checking enabled once again we should get a TypeCheckError here.
-    with self.assertRaises(TypeCheckError):
-      int_to_str(9)
-
-  def test_valid_mix_pos_and_keyword_with_both_orders(self):
-    @with_input_types(str, start=int)
-    @with_output_types(str)
-    def to_upper_with_slice(string, start):
-      return string.upper()[start:]
-
-    self.assertEqual('ELLO', to_upper_with_slice('hello', 1))
-
-  def test_simple_takes_and_returns_hints(self):
-    @check_type_hints
-    @with_output_types(str)
-    @with_input_types(a=str)
-    def to_lower(a):
-      return a.lower()
-
-    # Return type and argument type satisfied, should work as normal.
-    self.assertEqual('m', to_lower('M'))
-
-    # Invalid argument type should raise a TypeCheckError
-    with self.assertRaises(TypeCheckError):
-      to_lower(5)
-
-    @check_type_hints
-    @with_output_types(str)
-    @with_input_types(a=str)
-    def to_lower(a):
-      return 9
-
-    # Modified function now has an invalid return type.
-    with self.assertRaises(TypeCheckError):
-      to_lower('a')
-
-  def test_composite_takes_and_returns_hints(self):
-    @check_type_hints
-    @with_input_types(it=typehints.List[int])
-    @with_output_types(typehints.List[typehints.Tuple[int, int]])
-    def expand_ints(it):
-      return [(i, i + 1) for i in it]
-
-    # Return type and argument type satisfied, should work as normal.
-    self.assertEqual([(0, 1), (1, 2), (2, 3)], expand_ints(list(range(3))))
-
-    # Invalid argument, list of str instead of int.
-    with self.assertRaises(TypeCheckError):
-      expand_ints('t e s t'.split())
-
-    @check_type_hints
-    @with_output_types(typehints.List[typehints.Tuple[int, int]])
-    @with_input_types(it=typehints.List[int])
-    def expand_ints(it):
-      return [str(i) for i in it]
-
-    # Modified function now has invalid return type.
-    with self.assertRaises(TypeCheckError):
-      expand_ints(list(range(2)))
-
-
-class DecoratorHelpers(TypeHintTestCase):
-
-  def test_hint_helper(self):
-    self.assertTrue(typehints.is_consistent_with(Any, int))
-    self.assertTrue(typehints.is_consistent_with(int, Any))
-    self.assertTrue(typehints.is_consistent_with(str, object))
-    self.assertFalse(typehints.is_consistent_with(object, str))
-    self.assertTrue(typehints.is_consistent_with(str, Union[str, int]))
-    self.assertFalse(typehints.is_consistent_with(Union[str, int], str))
-
-  def test_positional_arg_hints(self):
-    self.assertEquals(typehints.Any, _positional_arg_hints('x', {}))
-    self.assertEquals(int, _positional_arg_hints('x', {'x': int}))
-    self.assertEquals(typehints.Tuple[int, typehints.Any],
-                      _positional_arg_hints(['x', 'y'], {'x': int}))
-
-  def test_getcallargs_forhints(self):
-    func = lambda a, (b, c), *d: None
-    self.assertEquals(
-        {'a': Any, 'b': Any, 'c': Any, 'd': Tuple[Any, ...]},
-        getcallargs_forhints(func, *[Any, Any]))
-    self.assertEquals(
-        {'a': Any, 'b': Any, 'c': Any, 'd': Tuple[Any, ...]},
-        getcallargs_forhints(func, *[Any, Any, Any, int]))
-    self.assertEquals(
-        {'a': int, 'b': str, 'c': Any, 'd': Tuple[Any, ...]},
-        getcallargs_forhints(func, *[int, Tuple[str, Any]]))
-
-if __name__ == '__main__':
-  unittest.main()

http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/b14dfadd/sdks/python/google/cloud/dataflow/utils/__init__.py
----------------------------------------------------------------------
diff --git a/sdks/python/google/cloud/dataflow/utils/__init__.py b/sdks/python/google/cloud/dataflow/utils/__init__.py
deleted file mode 100644
index ba1698d..0000000
--- a/sdks/python/google/cloud/dataflow/utils/__init__.py
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright 2016 Google Inc. All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-"""A package containing utilities."""
-
-# We must import path here to support the pattern of referencing utils.path
-# without needing to explicitly import google.cloud.dataflow.utils.path.
-import path



Mime
View raw message