You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/11/15 05:06:27 UTC
[GitHub] [beam] tvalentyn commented on a diff in pull request #24106: [Python]Support pipe operator as Union (PEP -604)
tvalentyn commented on code in PR #24106:
URL: https://github.com/apache/beam/pull/24106#discussion_r1022320625
##########
build.gradle.kts:
##########
@@ -328,7 +328,7 @@ tasks.register("pythonDockerBuildPreCommit") {
tasks.register("pythonLintPreCommit") {
// TODO(https://github.com/apache/beam/issues/20209): Find a better way to specify lint and formatter tasks without hardcoding py version.
- dependsOn(":sdks:python:test-suites:tox:py37:lint")
Review Comment:
we should lint against the lower version of python that we support. we should find how to exclude the file or portion of the code (perhaps by moving it to a different file), for the earlier version of the linter if necessary
##########
sdks/python/apache_beam/typehints/native_type_compatibility.py:
##########
@@ -176,6 +177,14 @@ def convert_to_beam_type(typ):
Raises:
ValueError: The type was malformed.
"""
+ # Convert `int | float` to typing.Union[int, float]
+ # pipe operator as Union and types.UnionType are introduced
+ # in Python 3.10.
+ # GH issue: https://github.com/apache/beam/issues/21972
+ if (sys.version_info.major == 3 and
+ sys.version_info.minor >= 10) and (isinstance(typ, types.UnionType)):
+ typ = typing.Union[typ]
Review Comment:
Let's add a test for this functionality. it would have to be enabled only for 3.10+.
--
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