Skip to content

Fix typing of methods for pyright #461

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

Merged
merged 1 commit into from
Jan 12, 2024
Merged

Fix typing of methods for pyright #461

merged 1 commit into from
Jan 12, 2024

Conversation

pvcnt
Copy link
Contributor

@pvcnt pvcnt commented Jan 12, 2024

What was changed

Since pyright 1.1.344, my code stated to fail with errors such as the following:

webapp.py:46:22 - error: No overloads for "execute_workflow" match the provided arguments (reportGeneralTypeIssues)
webapp.py:47:22 - error: Argument of type "(self: HelloWorkflow, name: str) -> Coroutine[Any, Any, str]" cannot be assigned to parameter "workflow" of type "str" in function "execute_workflow"
    "function" is incompatible with "str" (reportGeneralTypeIssues)

The code being something like:

@workflow.defn(name="HelloWorkflow")
class HelloWorkflow:
    @workflow.run
    async def run(self, name: str) -> str:
        return await workflow.execute_activity(
            hello_activity,
            HelloParams("Hello", name),
            start_to_close_timeout=timedelta(seconds=10),
        )

# and later in webapp.py:
return await env.temporal.execute_workflow(
    workflow=HelloWorkflow.run,
    arg="your name",
    id="workflow-id",
    task_queue="task-queue",
)

Despite looking legit, pyright did not like it. The issue is explained in microsoft/pyright#6875 and has to do with how the typing for methods is declared. I am attempting a fix here that I only tested with pyright for my use case, hoping that this will not break mypy.

Why?

To be able to use pyright with temporal.

Checklist

  1. How was this tested:
    Only a typing change, relying on CI to fully verify it.

  2. Any docs updates needed?
    No

@pvcnt pvcnt requested a review from a team as a code owner January 12, 2024 11:05
@CLAassistant
Copy link

CLAassistant commented Jan 12, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@cretz cretz left a comment

Choose a reason for hiding this comment

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

Thanks! This is passing our mypy CI checks (we have many calls that check the types there). I'll merge this now.

If you wanted to go further, you could add pyright as a CI step to ensure we don't break things like this in the future, but it'd also require doing whatever is necessary to make sure the SDK impl passes pyright instead of just the user-facing pieces. We'd totally support that effort of course, but understandable if you don't want to take that on.

@cretz cretz merged commit 10d099b into temporalio:main Jan 12, 2024
@pvcnt
Copy link
Contributor Author

pvcnt commented Jan 12, 2024

Thank you for the prompt review! Yes, I suppose having pyright checks built-in would be ideal. If I find some bandwidth I might give it a stab, but I'm not sure yet.

@pvcnt pvcnt deleted the patch-1 branch January 12, 2024 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants