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

Add support for using builtins typing #25054

Merged
merged 8 commits into from
Jan 19, 2023

Conversation

DavidKatz-il
Copy link
Contributor

@DavidKatz-il DavidKatz-il commented Jan 18, 2023

fixes #23366


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

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • 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.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

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

@github-actions
Copy link
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @AnandInguva for label python.

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

class TestBuiltinsTyping(unittest.TestCase):

def _assert_equal_convert_to_beam_type(self, type_a, type_b):
beam_type_a = native_type_compatibility.convert_to_beam_type(type_a)
Copy link
Contributor

Choose a reason for hiding this comment

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

These test would fail on Python 3.8 or lower since built-in type modules are supported from Python 3.9.

def test_convert_to_beam_type(self):
>       self._assert_equal_convert_to_beam_type(dict[str, int], typing.Dict[str, int])
E       TypeError: 'type' object is not subscriptable

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the changes made are compatible with Python 3.9 or above. @jrmccluskey is working on similar(same may be) issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

The proper way to handle this is to enable the unit tests and the behavior only on Python 3.9 and higher. #24986 does this for the added unit test cases, so this should be okay to do here

Copy link
Contributor

Choose a reason for hiding this comment

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

@DavidKatz-il Could you rebase on to HEAD and then run the tests?

@jrmccluskey
Copy link
Contributor

@DavidKatz-il I was actually working on this and had a short design doc in-flight, but I hadn't started the work on outlining the actual conversion mechanism yet. Would you be interested in writing up your solution in that doc and becoming a co-author?

@jrmccluskey
Copy link
Contributor

Here's a reference for linting and formatting in the Beam repo: https://cwiki.apache.org/confluence/display/BEAM/Python+Tips#PythonTips-LintandFormattingChecks

@DavidKatz-il
Copy link
Contributor Author

@DavidKatz-il I was actually working on this and had a short design doc in-flight, but I hadn't started the work on outlining the actual conversion mechanism yet. Would you be interested in writing up your solution in that doc and becoming a co-author?

@jrmccluskey
I apologize for not being aware that you were already addressing the issue. As this is my first contribution to the Beam project, I am uncertain if my proposed solution is the optimal one. It appears that the new test you added is failing due to the TypeError not being triggered.

@codecov
Copy link

codecov bot commented Jan 18, 2023

Codecov Report

Merging #25054 (9a4fb27) into master (b554040) will decrease coverage by 0.01%.
The diff coverage is 45.45%.

@@            Coverage Diff             @@
##           master   #25054      +/-   ##
==========================================
- Coverage   73.13%   73.13%   -0.01%     
==========================================
  Files         735      735              
  Lines       98151    98159       +8     
==========================================
+ Hits        71782    71784       +2     
- Misses      25006    25012       +6     
  Partials     1363     1363              
Flag Coverage Δ
python 82.67% <45.45%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...apache_beam/typehints/native_type_compatibility.py 82.82% <37.50%> (-2.34%) ⬇️
sdks/python/apache_beam/typehints/typehints.py 92.88% <66.66%> (-0.17%) ⬇️
.../python/apache_beam/testing/test_stream_service.py 88.09% <0.00%> (-4.77%) ⬇️
...che_beam/runners/interactive/interactive_runner.py 90.50% <0.00%> (-1.27%) ⬇️
...eam/runners/portability/fn_api_runner/execution.py 92.49% <0.00%> (-0.64%) ⬇️
...hon/apache_beam/runners/worker/bundle_processor.py 93.54% <0.00%> (+0.12%) ⬆️
...on/apache_beam/runners/dataflow/dataflow_runner.py 81.88% <0.00%> (+0.14%) ⬆️
sdks/go/pkg/beam/io/mongodbio/read.go 31.20% <0.00%> (+0.23%) ⬆️
sdks/python/apache_beam/runners/direct/executor.py 97.01% <0.00%> (+0.54%) ⬆️
... and 2 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jrmccluskey
Copy link
Contributor

Oh you're good! It's the nature of open source, collisions happen. The doc is at https://docs.google.com/document/d/1KgCnYlXDPi2SHtjuzkztUMpFfwgop29WishCI4dHZ30/edit?usp=sharing if you're interested in writing up your solution! Feel free to request editing access.

It's a good bridge solution while we support multiple Python versions on each side of the PEP 585 implementation. Eventually we'd have to replace everything with the built-in versions but that's at least two years off. You can remove those error-checking tests since your functionality eliminates the need for that error.

@jrmccluskey
Copy link
Contributor

Run Python_Integration PreCommit

@jrmccluskey
Copy link
Contributor

@damccorm

Copy link
Contributor

@jrmccluskey jrmccluskey left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@jrmccluskey jrmccluskey merged commit 6203e58 into apache:master Jan 19, 2023
@DavidKatz-il DavidKatz-il deleted the support_PEP_585_type_hints branch January 19, 2023 20:11
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.

3 participants