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
Conversation
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.
Codecov Report
@@ 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 Continue to review full report at Codecov.
|
Run PythonDocs PreCommit |
R: @yeandy |
Thanks, @robertwb |
Added missing opcodes for Python 3.8 and tests.
Added tests for dict/set update, which required adding some opcodes for <=3.8 as well. |
There was a problem hiding this 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[()]]) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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]], |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
11:27:16 Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed) |
Run Python PreCommit |
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:
R: @username
).[BEAM-XXX] Fixes bug in ApproximateQuantiles
, where you replaceBEAM-XXX
with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.CHANGES.md
with noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
ValidatesRunner
compliance status (on master branch)Examples testing status on various runners
Post-Commit SDK/Transform Integration Tests Status (on master branch)
Pre-Commit Tests Status (on master branch)
See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI.