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

Make client.py typecheck under pyright #628

Merged
merged 3 commits into from
Sep 6, 2024
Merged

Make client.py typecheck under pyright #628

merged 3 commits into from
Sep 6, 2024

Conversation

dandavison
Copy link
Contributor

No description provided.

Copy link
Member

@Sushisource Sushisource left a comment

Choose a reason for hiding this comment

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

Dope, thanks. Might be worth opening a ticket to see if we can somehow make the multi-arg stuff type properly.

Comment on lines +1115 to +1116
service_client: Required[temporalio.service.ServiceClient]
namespace: Required[str]
Copy link
Member

Choose a reason for hiding this comment

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

huh, weird, you think Required would be the default...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there's a fair amount of reading material on the topic for anyone so-inclined.
https://peps.python.org/pep-0655/
https://typing.readthedocs.io/en/latest/spec/typeddict.html#required-notrequired

Copy link
Member

@cretz cretz Aug 29, 2024

Choose a reason for hiding this comment

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

Hrmm, I am trying to remember why I did total=False here. Technically all of these config values are optional if you're using it as a typesafe way to provide parameters to Client.__init__. I wonder if I expected someone to do something like:

extra: client.ClientConfig = { "interceptors": [MyInterceptor()] }

# ...

new_client = Client(my_service_client, **extra)

This PR would break that use case. Also it means that if we ever add fields to __init__ we cannot make them required here if we want to be compatible with people that may be using this type. If we are ok breaking this use case, then I wonder if we should just remove total=False. I can't think of a reason that total=False should be there if every field is Required, can anyone else? Or if we want to allow these to be optional, no need for these new annotations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I'm not sure I should have merged without resolving this conversation. May need to revisit this. E.g. in features repo we attempt to do

register_feature(
    workflows=[Workflow],
    check_result=check_result,
    start=start,
    additional_client_config=ClientConfig(interceptors=[MyClientInterceptor()]),
)

https://github.com/temporalio/features/blob/bump-sdk-version/bin/main/update/client_interceptor/feature.py#L66

which isn't passing type checks.

@@ -3233,7 +3233,7 @@ class ScheduleActionStartWorkflow(ScheduleAction):
headers: Optional[Mapping[str, temporalio.api.common.v1.Payload]]

@staticmethod
def _from_proto(
def _from_proto( # pyright: ignore
Copy link
Member

Choose a reason for hiding this comment

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

Hrmm, I wonder if this is the same thing we ignore in the system-agnostic way below and pyright just cares about the line the declaration started instead of the param.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that's right. It's a bit silly having a cluster of type-ignore annotations for different type-checkers but I played around with a few variations and this is what passed.

@@ -3489,7 +3489,7 @@ class ScheduleOverlapPolicy(IntEnum):
"""

SKIP = int(
temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_SKIP
temporalio.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_SKIP # pyright: ignore
Copy link
Member

Choose a reason for hiding this comment

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

I am curious, what is the issue on this one? There is ValueType = typing.NewType("ValueType", builtins.int) on the proto side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call drawing attention to that. It didn't make sense as a pyright false positive to an extent that it needed looking into. The pyright: ignores aren't the right solution; looks like the dataclass decorator is accidental.

@dandavison dandavison force-pushed the pyright-fixes-1 branch 4 times, most recently from e0f70da to 5efb27d Compare September 6, 2024 14:05
@dandavison dandavison merged commit 59d04a6 into main Sep 6, 2024
12 checks passed
@dandavison dandavison deleted the pyright-fixes-1 branch September 6, 2024 22:41
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