Skip to content

Commit

Permalink
This closes #1902
Browse files Browse the repository at this point in the history
  • Loading branch information
aaltay committed Feb 3, 2017
2 parents 1533d70 + c0eef13 commit 96a05a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 8 additions & 3 deletions sdks/python/apache_beam/transforms/core.py
Expand Up @@ -21,6 +21,7 @@

import copy
import inspect
import warnings
import types

from apache_beam import pvalue
Expand Down Expand Up @@ -216,7 +217,7 @@ def is_process_bounded(self):


# TODO(Sourabh): Remove after migration to NewDoFn
class DoFn(WithTypeHints, HasDisplayData):
class OldDoFn(WithTypeHints, HasDisplayData):
"""A function object used by a transform with custom processing.
The ParDo transform is such a transform. The ParDo.expand()
Expand All @@ -228,6 +229,10 @@ class DoFn(WithTypeHints, HasDisplayData):
callable object using the CallableWrapperDoFn class.
"""

def __init__(self):
warnings.warn('Use of OldDoFn is deprecated please use DoFn instead')
super(OldDoFn, self).__init__()

def default_label(self):
return self.__class__.__name__

Expand Down Expand Up @@ -674,7 +679,7 @@ class ParDo(PTransformWithSideInputs):
def __init__(self, fn_or_label, *args, **kwargs):
super(ParDo, self).__init__(fn_or_label, *args, **kwargs)

if not isinstance(self.fn, (DoFn, NewDoFn)):
if not isinstance(self.fn, (OldDoFn, NewDoFn)):
raise TypeError('ParDo must be called with a DoFn instance.')

def default_type_hints(self):
Expand All @@ -685,7 +690,7 @@ def infer_output_type(self, input_type):
self.fn.infer_output_type(input_type))

def make_fn(self, fn):
if isinstance(fn, (DoFn, NewDoFn)):
if isinstance(fn, (OldDoFn, NewDoFn)):
return fn
return CallableWrapperDoFn(fn)

Expand Down
8 changes: 5 additions & 3 deletions sdks/python/apache_beam/typehints/typecheck.py
Expand Up @@ -23,7 +23,7 @@
import types

from apache_beam.pvalue import SideOutputValue
from apache_beam.transforms.core import DoFn
from apache_beam.transforms.core import OldDoFn
from apache_beam.transforms.core import NewDoFn
from apache_beam.transforms.window import WindowedValue
from apache_beam.typehints import check_constraint
Expand All @@ -35,7 +35,8 @@
from apache_beam.typehints.decorators import getcallargs_forhints


class TypeCheckWrapperDoFn(DoFn):
# TODO(Sourabh): Remove after migration to NewDoFn
class TypeCheckWrapperDoFn(OldDoFn):
"""A wrapper around a DoFn which performs type-checking of input and output.
"""

Expand Down Expand Up @@ -123,7 +124,8 @@ def _type_check(self, type_constraint, datum, is_input):
raise TypeCheckError, error_msg, sys.exc_info()[2]


class OutputCheckWrapperDoFn(DoFn):
# TODO(Sourabh): Remove after migration to NewDoFn
class OutputCheckWrapperDoFn(OldDoFn):
"""A DoFn that verifies against common errors in the output type."""

def __init__(self, dofn, full_label):
Expand Down

0 comments on commit 96a05a4

Please sign in to comment.