You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "jrmccluskey (via GitHub)" <gi...@apache.org> on 2024/12/19 20:44:10 UTC
[PR] Update typehinting code to use primitives and collections types as main types over typing variants [beam]
jrmccluskey opened a new pull request, #33427:
URL: https://github.com/apache/beam/pull/33427
Updates the typehinting module (particularly native_type_compatibility.py) to process primitives and collections types as first-class citizens over typing equivalents to respect PEP-585 typing conventions.
DO NOT MERGE until converting from beam types is updated as well.
------------------------
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](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Update typehinting code to use primitives and collections types as main types over typing variants [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #33427:
URL: https://github.com/apache/beam/pull/33427#issuecomment-2573691890
Assigning reviewers. If you would like to opt out of this review, comment `assign to next reviewer`:
R: @damccorm 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).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Update typehinting code to use primitives and collections types as main types over typing variants [beam]
Posted by "jrmccluskey (via GitHub)" <gi...@apache.org>.
jrmccluskey commented on code in PR #33427:
URL: https://github.com/apache/beam/pull/33427#discussion_r1905691012
##########
sdks/python/apache_beam/typehints/native_type_compatibility.py:
##########
@@ -99,14 +115,25 @@ def _match_issubclass(match_against):
return lambda user_type: _safe_issubclass(user_type, match_against)
+def _is_primative(user_type, primative):
Review Comment:
fixed
##########
sdks/python/apache_beam/typehints/native_type_compatibility.py:
##########
@@ -197,6 +226,36 @@ def convert_builtin_to_typing(typ):
return typ
+def convert_typing_to_builtin(typ):
+ """Converts a given typing collections type to its builtin counterpart.
+
+ Args:
+ typ: A typing type (e.g., typing.List[int]).
+
+ Returns:
+ type: The corresponding builtin type (e.g., list).
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Update typehinting code to use primitives and collections types as main types over typing variants [beam]
Posted by "jrmccluskey (via GitHub)" <gi...@apache.org>.
jrmccluskey commented on PR #33427:
URL: https://github.com/apache/beam/pull/33427#issuecomment-2573689756
assign set of reviewers
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Update typehinting code to use primitives and collections types as main types over typing variants [beam]
Posted by "jrmccluskey (via GitHub)" <gi...@apache.org>.
jrmccluskey commented on code in PR #33427:
URL: https://github.com/apache/beam/pull/33427#discussion_r1905687490
##########
sdks/python/apache_beam/typehints/native_type_compatibility.py:
##########
@@ -216,6 +275,24 @@ def convert_collections_to_typing(typ):
return typ
+def is_builtin(typ):
+ if typ in _BUILTINS:
+ return True
+ return getattr(typ, '__origin__', None) in _BUILTINS
+
+
+# During type inference of WindowedValue, we need to pass in the inner value
+# type. This cannot be achieved immediately with WindowedValue class because it
+# is not parameterized. Changing it to a generic class (e.g. WindowedValue[T])
+# could work in theory. However, the class is cythonized and it seems that
+# cython does not handle generic classes well.
+# The workaround here is to create a separate class solely for the type
+# inference purpose. This class should never be used for creating instances.
+class TypedWindowedValue(Generic[T]):
Review Comment:
Oh I see what happened, this got mixed in when I dealt with merge conflicts. This was from Shunping's work on the reshuffle coder issue, but that PR was reverted at some point. I'll remove this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Update typehinting code to use primitives and collections types as main types over typing variants [beam]
Posted by "damccorm (via GitHub)" <gi...@apache.org>.
damccorm commented on code in PR #33427:
URL: https://github.com/apache/beam/pull/33427#discussion_r1905675980
##########
sdks/python/apache_beam/typehints/native_type_compatibility.py:
##########
@@ -216,6 +275,24 @@ def convert_collections_to_typing(typ):
return typ
+def is_builtin(typ):
+ if typ in _BUILTINS:
+ return True
+ return getattr(typ, '__origin__', None) in _BUILTINS
+
+
+# During type inference of WindowedValue, we need to pass in the inner value
+# type. This cannot be achieved immediately with WindowedValue class because it
+# is not parameterized. Changing it to a generic class (e.g. WindowedValue[T])
+# could work in theory. However, the class is cythonized and it seems that
+# cython does not handle generic classes well.
+# The workaround here is to create a separate class solely for the type
+# inference purpose. This class should never be used for creating instances.
+class TypedWindowedValue(Generic[T]):
Review Comment:
It doesn't look like we actually use this class yet - is that right? If so, should we just defer this change until we need it?
##########
sdks/python/apache_beam/typehints/native_type_compatibility.py:
##########
@@ -197,6 +226,36 @@ def convert_builtin_to_typing(typ):
return typ
+def convert_typing_to_builtin(typ):
+ """Converts a given typing collections type to its builtin counterpart.
+
+ Args:
+ typ: A typing type (e.g., typing.List[int]).
+
+ Returns:
+ type: The corresponding builtin type (e.g., list).
Review Comment:
```suggestion
type: The corresponding builtin type (e.g., list[int]).
```
Nit: this should still match the input, right?
##########
sdks/python/apache_beam/typehints/native_type_compatibility.py:
##########
@@ -99,14 +115,25 @@ def _match_issubclass(match_against):
return lambda user_type: _safe_issubclass(user_type, match_against)
+def _is_primative(user_type, primative):
Review Comment:
```suggestion
def _is_primitive(user_type, primative):
```
Nit: here and elsewhere
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Update typehinting code to use primitives and collections types as main types over typing variants [beam]
Posted by "jrmccluskey (via GitHub)" <gi...@apache.org>.
jrmccluskey merged PR #33427:
URL: https://github.com/apache/beam/pull/33427
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org