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

Improve taskflow type hints with ParamSpec #25173

Merged
merged 2 commits into from
Jul 26, 2022

Conversation

uranusjr
Copy link
Member

@uranusjr uranusjr commented Jul 20, 2022

This needs #25085 to be merged first. Only the last commit is relevant.

Submitted for CI now.

This should be ready. I needed to fix a few more (valid although unrelated) typing issues since Mypy started to flag them.

The main thing here is to replace the Function type var with Callable[FParams, FReturn] so we can do polymorphism against FParams without being tied to FReturn.

@uranusjr uranusjr marked this pull request as ready for review July 25, 2022 04:27
This is made available with our latest Mypy update. ParamSpec allows us
to more accurately type a decorated task to return an XComArg (while
still being correctly typed to accept the same arguments as the
decorated function). This allows us to provide autocompletion for
XComArg operations, such as map() and zip() introduced in AIP-42.
Copy link
Member

@ashb ashb left a comment

Choose a reason for hiding this comment

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

One question. LGTM otherwise if that's not possible

@@ -47,7 +47,7 @@ class SalesforceBulkOperator(BaseOperator):
def __init__(
self,
*,
operation: Literal[available_operations],
operation: Literal['insert', 'update', 'upsert', 'delete', 'hard_delete'],
Copy link
Member

Choose a reason for hiding this comment

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

Is it not possible to do

Suggested change
operation: Literal['insert', 'update', 'upsert', 'delete', 'hard_delete'],
operation: Literal[*available_operations],

Copy link
Member Author

@uranusjr uranusjr Jul 26, 2022

Choose a reason for hiding this comment

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

Python syntactically does not allow using * in brackets. The previous Literal[available_operations] is valid Python but PEP 586 considered this out of scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:dev-tools type:improvement Changelog: Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants