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 collections.abc.Collection type hints #29272

Merged
merged 5 commits into from
Nov 7, 2023

Conversation

jrmccluskey
Copy link
Contributor

Adds a new internal Beam representation for type hints that are exactly collections.abc.Collections types. Allows for more general type hinting guarantees.

Part of #29135


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 or the workflows README to see a list of phrases to trigger workflows.

Copy link

codecov bot commented Nov 2, 2023

Codecov Report

Merging #29272 (a1f920a) into master (f98063c) will increase coverage by 0.00%.
Report is 32 commits behind head on master.
The diff coverage is 44.44%.

❗ Current head a1f920a differs from pull request most recent head c2148fa. Consider uploading reports for the commit c2148fa to get more accurate results

@@           Coverage Diff           @@
##           master   #29272   +/-   ##
=======================================
  Coverage   38.30%   38.30%           
=======================================
  Files         690      690           
  Lines      102043   102072   +29     
=======================================
+ Hits        39085    39097   +12     
- Misses      61375    61392   +17     
  Partials     1583     1583           
Flag Coverage Δ
python 29.88% <44.44%> (+<0.01%) ⬆️

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

Files Coverage Δ
...apache_beam/typehints/native_type_compatibility.py 55.19% <100.00%> (+0.49%) ⬆️
sdks/python/apache_beam/typehints/typehints.py 50.00% <40.00%> (-0.48%) ⬇️

... and 1 file with indirect coverage changes

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

Copy link
Contributor

github-actions bot commented Nov 2, 2023

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

R: @johnjcasey added as fallback since no labels match configuration

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).

@jrmccluskey
Copy link
Contributor Author

R: @damccorm @robertwb

Copy link
Contributor

github-actions bot commented Nov 2, 2023

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control

Copy link
Contributor

@damccorm damccorm left a comment

Choose a reason for hiding this comment

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

Generally LGTM, had a couple minor questions/comments

sdks/python/apache_beam/typehints/typehints.py Outdated Show resolved Hide resolved
is_consistent_with(elem, self.inner_type)
for elem in sub.tuple_types)
elif not isinstance(sub, TypeConstraint):
if getattr(sub, '__origin__', None) is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this check? I would've assumed issubclass would take care of it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Parameterized generics and issubclass do not get along. If you pass along a parameterized type (something like issubclass(set[int], collections.abc.Collection)) you actually get an error that the first arg has to be a class. This is why the internal checking for these containers separates out the container type from the type it wraps and checks them separately.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it - thanks

Copy link
Contributor

@damccorm damccorm left a comment

Choose a reason for hiding this comment

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

LGTM

@jrmccluskey jrmccluskey merged commit 1c24bc9 into apache:master Nov 7, 2023
71 checks passed
@jrmccluskey jrmccluskey deleted the collectorsEdition branch November 7, 2023 15: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