-
Notifications
You must be signed in to change notification settings - Fork 71
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
Conversation
d6b43fe
to
ddd669b
Compare
There was a problem hiding this 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.
service_client: Required[temporalio.service.ServiceClient] | ||
namespace: Required[str] |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()]),
)
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
temporalio/client.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: ignore
s aren't the right solution; looks like the dataclass decorator is accidental.
e0f70da
to
5efb27d
Compare
No description provided.