8000 [BEAM-7746] Add python type hints (part 1) by chadrik · Pull Request #9915 · apache/beam · GitHub
[go: up one dir, main page]

Skip to content

[BEAM-7746] Add python type hints (part 1) #9915

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

Merged
merged 17 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address issues with a few missing modules/objects
  • Loading branch information
chadrik committed Dec 9, 2019
commit 70f06ed70dca61f0482fb0af17f7b7f1b90e72d3
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/options/pipeline_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def __init__(self, flags=None, **kwargs):
if cls == PipelineOptions:
break
elif '_add_argparse_args' in cls.__dict__:
cls._add_argparse_args(parser)
cls._add_argparse_args(parser) # type: ignore

# The _visible_options attribute will contain options that were recognized
# by the parser.
Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/pvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def __getattr__(self, tag):
# Special methods which may be accessed before the object is
# fully constructed (e.g. in unpickling).
if tag[:2] == tag[-2:] == '__':
return object.__getattr__(self, tag)
return object.__getattr__(self, tag) # type: ignore
return self[tag]

def __getitem__(self, tag):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import collections
import threading
import time
import typing

from apache_beam.runners.interactive.display import interactive_pipeline_graph

Expand All @@ -37,11 +38,12 @@
# _display_progress defines how outputs are printed on the frontend.
_display_progress = ip_display

def _formatter(string, pp, cycle): # pylint: disable=unused-argument
pp.text(string)
if get_ipython():
plain = get_ipython().display_formatter.formatters['text/plain'] # pylint: disable=undefined-variable
plain.for_type(str, _formatter)
if not typing.TYPE_CHECKING:
def _formatter(string, pp, cycle): # pylint: disable=unused-argument
pp.text(string)
if get_ipython():
plain = get_ipython().display_formatter.formatters['text/plain'] # pylint: disable=undefined-variable
plain.for_type(str, _formatter)

except ImportError:
IPython = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from builtins import object

import grpc
from google.protobuf import text_format
from google.protobuf import text_format # type: ignore # not in typeshed

from apache_beam.metrics import monitoring_infos
from apache_beam.portability.api import beam_artifact_api_pb2
Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/runners/worker/sdk_worker_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import traceback
from builtins import object

from google.protobuf import text_format
from google.protobuf import text_format # type: ignore # not in typeshed

from apache_beam.internal import pickler
from apache_beam.options.pipeline_options import DebugOptions
Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/runners/worker/statesampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from apache_beam.utils.counters import CounterName

try:
from apache_beam.runners.worker import statesampler_fast as statesampler_impl
from apache_beam.runners.worker import statesampler_fast as statesampler_impl # type: ignore
FAST_SAMPLER = True
except ImportError:
from apache_beam.runners.worker import statesampler_slow as statesampler_impl
Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/typehints/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def get_type_hints(fn):
hints = IOTypeHints()
# Python 3.7 introduces annotations for _MethodDescriptorTypes.
if isinstance(fn, _MethodDescriptorType) and sys.version_info < (3, 7):
hints.set_input_types(fn.__objclass__)
hints.set_input_types(fn.__objclass__) # type: ignore
return hints
return fn._type_hints
# pylint: enable=protected-access
Expand Down
2 changes: 1 addition & 1 deletion sdks/python/apache_beam/typehints/trivial_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
try: # Python 2
import __builtin__ as builtins
except ImportError: # Python 3
import builtins
import builtins # type: ignore
# pylint: enable=wrong-import-order, wrong-import-position, ungrouped-imports


Expand Down
0