Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEAM-886] Rename DoFn to OldDoFn and add deprecation message #1902

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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