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

Add type annotations to socket_client.py #805

Merged
merged 2 commits into from
Jan 30, 2024

Conversation

emontnemery
Copy link
Collaborator

No description provided.

Comment on lines -405 to -407
else:
retry_log_fun(
"[%s(%s):%s] Failed to connect, retrying in %.1fs",
self.fn or "",
self.host,
self.port,
self.retry_wait,
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should have been cleaned up as part of #556

msg.namespace = namespace
msg.payload_utf8 = _json_to_payload(data)
msg.payload_utf8 = _json_to_payload(data) # type: ignore[assignment]
Copy link
Collaborator Author

@emontnemery emontnemery Jan 28, 2024

Choose a reason for hiding this comment

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

The code works, but violates the typing of CastMessage which says CastMessage.payload_utf8 should be a str.

Edit:
After some debugging of the pure Python version of protobuf, it turns our that the bytes provided by us is decoded to a str here: https://github.com/protocolbuffers/protobuf/blob/1d6ac5979b909a222db45cb154f0be3a31828324/python/google/protobuf/internal/type_checkers.py#L189, and then encoded again here: https://github.com/protocolbuffers/protobuf/blob/1d6ac5979b909a222db45cb154f0be3a31828324/python/google/protobuf/internal/encoder.py#L678

This is clearly a waste of CPU time, fixed in PR #806

@MartinHjelmare
Copy link
Contributor

There's a merge conflict.

@MartinHjelmare MartinHjelmare merged commit f46abde into master Jan 30, 2024
1 check passed
@MartinHjelmare MartinHjelmare deleted the type_annotations_socket_client branch January 30, 2024 07:53
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.

2 participants