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-12914] Add missing 3.9 opcodes to type inference. #16761

Merged
merged 3 commits into from Feb 8, 2022

Conversation

robertwb
Copy link
Contributor

@robertwb robertwb commented Feb 7, 2022

Also fix the list/tuple unpack opcodes, which cannot assume there is
exactly one (or even any) item in each argument. Unfortuantely this
weakens some of the type inference.


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.

ValidatesRunner compliance status (on master branch)

Lang ULR Dataflow Flink Samza Spark Twister2
Go --- Build Status 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
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 ---
XLang Build Status Build Status
Build Status
Build Status
Build Status Build Status Build Status ---

Examples testing status on various runners

Lang ULR Dataflow Flink Samza Spark Twister2
Go --- --- --- --- --- --- ---
Java --- Build Status
Build Status
Build Status
--- --- --- --- ---
Python --- --- --- --- --- --- ---
XLang --- --- --- --- --- --- ---

Post-Commit SDK/Transform Integration Tests Status (on master branch)

Go Java Python
Build Status Build Status Build Status
Build Status
Build Status

Pre-Commit Tests Status (on master branch)

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

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

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests

See CI.md for more information about GitHub Actions CI.

Also fix the list/tuple unpack opcodes, which cannot assume there is
exactly one (or even any) item in each argument.  Unfortuantely this
weakens some of the type inference.
@github-actions github-actions bot added the python label Feb 7, 2022
@codecov
Copy link

codecov bot commented Feb 7, 2022

Codecov Report

Merging #16761 (b9247c3) into master (07e1f84) will increase coverage by 37.16%.
The diff coverage is 63.33%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master   #16761       +/-   ##
===========================================
+ Coverage   46.45%   83.61%   +37.16%     
===========================================
  Files         202      452      +250     
  Lines       19914    62233    +42319     
===========================================
+ Hits         9251    52038    +42787     
- Misses       9674    10195      +521     
+ Partials      989        0      -989     
Impacted Files Coverage Δ
sdks/python/apache_beam/typehints/opcodes.py 84.89% <61.11%> (ø)
.../python/apache_beam/typehints/trivial_inference.py 96.41% <83.33%> (ø)
sdks/go/pkg/beam/transforms/stats/sum_switch.go
sdks/go/pkg/beam/core/util/hooks/hooks.go
...kg/beam/core/runtime/xlangx/expansionx/download.go
sdks/go/pkg/beam/partition.go
sdks/go/pkg/beam/transforms/stats/count.go
sdks/go/pkg/beam/core/runtime/metricsx/urns.go
sdks/go/pkg/beam/core/graph/coder/coder.go
sdks/go/pkg/beam/runners/direct/direct.go
... and 646 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 07e1f84...b9247c3. Read the comment docs.

@robertwb
Copy link
Contributor Author

robertwb commented Feb 7, 2022

Run PythonDocs PreCommit

@robertwb
Copy link
Contributor Author

robertwb commented Feb 7, 2022

R: @yeandy
CC: @tvalentyn

@tvalentyn
Copy link
Contributor

Thanks, @robertwb
Docs failure tracked in https://issues.apache.org/jira/browse/BEAM-13848.
We should add unittests for new dict operation, but I am ok to do that later in BEAM-13843.

Added missing opcodes for Python 3.8 and tests.
@robertwb
Copy link
Contributor Author

robertwb commented Feb 8, 2022

Added tests for dict/set update, which required adding some opcodes for <=3.8 as well.

Copy link
Contributor

@yeandy yeandy left a comment

Choose a reason for hiding this comment

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

LGTM.

I added a few questions to clarify my understanding.

@@ -260,6 +262,13 @@ def build_list(state, arg):
state.stack[-arg:] = [List[reduce(union, state.stack[-arg:], Union[()])]]


def build_set(state, arg):
if arg == 0:
state.stack.append(List[Union[()]])
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we appending a List instead of Set to the stack?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. This should be list. I think this is missing in our tests because it's there's no empty set literal in Python, but I added some tests for set comprehension that exercise this.

@@ -308,13 +329,15 @@ def fn(x1, x2, *unused_args):
return x1, x2

self.assertReturnType(
typehints.Tuple[str, float],
typehints.Tuple[typehints.Union[str, float, int],
typehints.Union[str, float, int]],
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the more robust typehinting in action here for tuple unpacking. Nice!

@@ -227,6 +227,9 @@ def element_type(hint):
return hint.inner_type
elif isinstance(hint, typehints.TupleHint.TupleConstraint):
return typehints.Union[hint.tuple_types]
elif isinstance(hint,
typehints.UnionHint.UnionConstraint) and not hint.union_types:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you help me better understand why we're also requiring the not hint.union_types part?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The empty union is a type that can never happen; we want to propagate that to its (non-existent) "element" type.

@robertwb
Copy link
Contributor Author

robertwb commented Feb 8, 2022

11:27:16 Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)

@robertwb
Copy link
Contributor Author

robertwb commented Feb 8, 2022

Run Python PreCommit

@tvalentyn tvalentyn merged commit b09f51a into apache:master Feb 8, 2022
@tvalentyn
Copy link
Contributor

Thanks, @robertwb and @yeandy !

Naireen pushed a commit to Naireen/beam that referenced this pull request Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants