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

feat: Support pep604 union operator #2298

Merged
merged 29 commits into from
Mar 27, 2024
Merged

feat: Support pep604 union operator #2298

merged 29 commits into from
Mar 27, 2024

Conversation

ggydush
Copy link
Collaborator

@ggydush ggydush commented Mar 27, 2024

Tracking issue

Closes flyteorg/flyte#4706

Why are the changes needed?

Python 3.10 introduced the ability to write union types using | rather than importing from typing (e.g., int | str instead of typing.Union[int, str]), and I believe this should be supported. See PEP 604.

What changes were proposed in this pull request?

How was this patch tested?

Added unit tests and registered a large code base with the updated Flytekit and tested a workflow on remote. Ran a small test locally on Python 3.8 too to ensure correct error is bubbled up:

│ ❱  5 def process(a: int | None) -> int:                                                                                                                                      │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

Setup process

Screenshots

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

Docs link

Copy link

codecov bot commented Mar 27, 2024

Codecov Report

Attention: Patch coverage is 86.66667% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 83.46%. Comparing base (fa2aa0b) to head (fda183f).
Report is 2 commits behind head on master.

Files Patch % Lines
flytekit/core/type_engine.py 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2298      +/-   ##
==========================================
- Coverage   83.89%   83.46%   -0.44%     
==========================================
  Files         342      324      -18     
  Lines       25483    24716     -767     
  Branches     3725     3516     -209     
==========================================
- Hits        21380    20630     -750     
+ Misses       3472     3452      -20     
- Partials      631      634       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

ggydush added 12 commits March 27, 2024 08:22
Signed-off-by: ggydush <[email protected]>
Signed-off-by: ggydush <[email protected]>
Signed-off-by: ggydush <[email protected]>
Signed-off-by: ggydush <[email protected]>
Signed-off-by: ggydush <[email protected]>
Signed-off-by: ggydush <[email protected]>
Signed-off-by: ggydush <[email protected]>
Signed-off-by: ggydush <[email protected]>
@ggydush ggydush force-pushed the ggydush/support-pep604 branch from f5e7ca2 to dff23cb Compare March 27, 2024 15:22
@ggydush ggydush marked this pull request as ready for review March 27, 2024 15:22
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 27, 2024
Copy link
Member

@pingsutw pingsutw left a comment

Choose a reason for hiding this comment

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

Thank you so much! Many people are asking about this feature

flytekit/core/type_engine.py Outdated Show resolved Hide resolved
flytekit/core/type_engine.py Outdated Show resolved Hide resolved
flytekit/core/type_engine.py Outdated Show resolved Hide resolved
ggydush and others added 4 commits March 27, 2024 13:06
@ggydush ggydush requested a review from pingsutw March 27, 2024 20:16
@ggydush ggydush requested a review from pingsutw March 27, 2024 20:29
Signed-off-by: ggydush <[email protected]>
pingsutw
pingsutw previously approved these changes Mar 27, 2024
tests/flytekit/unit/core/test_interface.py Show resolved Hide resolved
@dosubot dosubot bot added the lgtm This PR has been approved by maintainer label Mar 27, 2024
Copy link
Collaborator

@eapolinario eapolinario left a comment

Choose a reason for hiding this comment

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

This is awesome!

flytekit/core/type_engine.py Show resolved Hide resolved
tests/flytekit/unit/core/test_interface.py Show resolved Hide resolved
eapolinario
eapolinario previously approved these changes Mar 27, 2024
Signed-off-by: ggydush <[email protected]>
@ggydush ggydush merged commit 312c92f into master Mar 27, 2024
47 of 48 checks passed
fiedlerNr9 pushed a commit that referenced this pull request Jul 25, 2024
* feat: Support pep604 union operator

Signed-off-by: ggydush <[email protected]>

* fix: check union early

Signed-off-by: ggydush <[email protected]>

* refactor: Change name to 604

Signed-off-by: ggydush <[email protected]>

* fix lint

Signed-off-by: ggydush <[email protected]>

* fix: Fix duplicated code

Signed-off-by: ggydush <[email protected]>

* fix: Remove code for testing

Signed-off-by: ggydush <[email protected]>

* test: Add simple tests

Signed-off-by: ggydush <[email protected]>

* Add more tests

Signed-off-by: ggydush <[email protected]>

* fix: Fix names

Signed-off-by: ggydush <[email protected]>

* fix: Lint

Signed-off-by: ggydush <[email protected]>

* fix: Fix again

Signed-off-by: ggydush <[email protected]>

* fix: Fix default

Signed-off-by: ggydush <[email protected]>

* test: Add test for parameter and defaults

Signed-off-by: ggydush <[email protected]>

* fix: Fix code coverage by ignoring

Signed-off-by: ggydush <[email protected]>

* refactor: Use is_union_type

Signed-off-by: ggydush <[email protected]>

* fix import sort

Signed-off-by: ggydush <[email protected]>

* fix: cleanup

Signed-off-by: ggydush <[email protected]>

* fix: fix

Signed-off-by: ggydush <[email protected]>

* refactor: Clean it up

Signed-off-by: ggydush <[email protected]>

* fix: Fix lint

Signed-off-by: ggydush <[email protected]>

* fix: Fix pydantic plugin test failure

Signed-off-by: ggydush <[email protected]>

* Update flytekit/core/type_engine.py

Co-authored-by: Kevin Su <[email protected]>

* Address comment

Signed-off-by: ggydush <[email protected]>

* fix: Use UnionTransformer

Signed-off-by: ggydush <[email protected]>

* fix: Fix lint

Signed-off-by: ggydush <[email protected]>

* Skip tests with | syntax on < 3.10

Signed-off-by: ggydush <[email protected]>

* fix: Fix test

Signed-off-by: ggydush <[email protected]>

* fix: More review comments

Signed-off-by: ggydush <[email protected]>

* fix: Fix lint

Signed-off-by: ggydush <[email protected]>

---------

Signed-off-by: ggydush <[email protected]>
Co-authored-by: Kevin Su <[email protected]>
Signed-off-by: Jan Fiedler <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Flytekit python unable to parse int | None style type hints on python3.11
3 participants