Skip to content

[BEAM-9296] Clean up and add type-hints to SDF API#10935

Merged
boyuanzz merged 3 commits into
apache:masterfrom
boyuanzz:type_hint
Feb 24, 2020
Merged

[BEAM-9296] Clean up and add type-hints to SDF API#10935
boyuanzz merged 3 commits into
apache:masterfrom
boyuanzz:type_hint

Conversation

@boyuanzz
Copy link
Copy Markdown
Contributor

R: @chadrik


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

Post-Commit Tests Status (on master branch)

Lang SDK Apex Dataflow Flink Gearpump Samza Spark
Go Build Status --- --- Build Status --- --- Build Status
Java Build Status Build Status Build Status Build Status
Build Status
Build Status
Build Status Build Status Build Status
Build Status
Build Status
Python Build Status
Build Status
Build Status
Build Status
--- Build Status
Build Status
Build Status
Build Status
--- --- Build Status
XLang --- --- --- Build Status --- --- Build Status

Pre-Commit Tests Status (on master branch)

--- Java Python Go Website
Non-portable Build Status Build Status
Build Status
Build Status Build Status
Portable --- Build Status --- ---

See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.

@boyuanzz
Copy link
Copy Markdown
Contributor Author

cc: @robertwb

Copy link
Copy Markdown
Contributor

@chadrik chadrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just two minor notes. Thanks for following up on this!


if TYPE_CHECKING:
from apache_beam.io.iobase import RestrictionTracker
from apache_beam.io.iobase import RestrictionProgress
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our linters do not enforce alphanumeric order for modules inside the TYPE_CHECKING block, but we should still be diligent about it. Can you move this up one, please.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks for mentioning that!

return self.get_restriction_provider() is not None

def get_restriction_coder(self):
# type: () -> Optional[TupleCoder]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A slight refactor here will avoid introducing a new mypy error:

  def get_restriction_coder(self):
    # type: () -> Optional[TupleCoder]
    """Get coder for a restriction when processing an SDF. """
    if self.is_splittable_dofn():
      return TupleCoder([
          (self.get_restriction_provider().restriction_coder()),
          (self.get_watermark_estimator_provider().estimator_state_coder())
      ])
    else:
      return None

This avoids having to declare the restriction_coder variable as Optional[TupleCoder].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I think the return type should still be Optional[TupleCoder] given that it also returns None.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct. my comment about avoiding the declaration of Optional[TupleCoder] refers to the variable (which my edit does away with), not the the return type.

@chadrik
Copy link
Copy Markdown
Contributor

chadrik commented Feb 24, 2020

LGTM, assuming the tests pass.

@boyuanzz
Copy link
Copy Markdown
Contributor Author

All tests passed. I'm going to merge it. Thanks, Chad!

@boyuanzz boyuanzz merged commit 3169579 into apache:master Feb 24, 2020
@boyuanzz boyuanzz deleted the type_hint branch March 5, 2020 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants