Skip to content

Chore/fix type hints and general clarity #57

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

Conversation

ouatu-ro
Copy link
Contributor

Cleared all type hint errors for better clarity.
I have also added an assert inside must_take_notification to ensure it only returns bytes or None.
Can you confirm that this is correct? Should it not return str or list[str], as those are strictly associated with an invocation ID or a state keys response?

… files

- Updated type hints for methods in context, handler, server_context, and service modules to improve type safety and clarity.
- Removed unnecessary `# type: ignore` comments where type hints are now correctly specified.
- General code cleanup for better readability and maintainability.
…tness issues, as the method is not currently utilized elsewhere.
@ouatu-ro ouatu-ro marked this pull request as ready for review March 20, 2025 14:21
…server_context modules

- Updated the __await__ method signatures in RestateDurableFuture and ServerDurableFuture to specify return types as typing.Generator.
- Changed the state_keys method return type in ServerInvocationContext to RestateDurableFuture[List[str]] for improved type safety.
- Refined the create_df method to handle various notification types and added detailed docstring for clarity.
- Ensured consistent handling of notification types across methods in ServerInvocationContext.
@ouatu-ro ouatu-ro force-pushed the chore/fix-type-hints-and-general-clarity branch from f7ec282 to 06772d8 Compare March 20, 2025 16:44
Copy link
Contributor

@igalshilman igalshilman left a comment

Choose a reason for hiding this comment

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

Hey @ouatu-ro,
thanks a lot for taking this chore, very much appreciated.

I'm afraid you'd need to rebase one more time, as i had to make some changes today, as i've discovered some issues and refactored a bit to make the whole futures handling way more robust.

Some of the code that you've annotated doesn't exists anymore.

Copy link
Contributor

@igalshilman igalshilman left a comment

Choose a reason for hiding this comment

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

Really good and helpful work @ouatu-ro, thank you for taking the time to adopt the type annotations etc'.

There are two or 3 comments I've left that i'd kindly like to ask you to address.
And then LGTM!

if not self.vm.is_completed(handle):
await self.create_poll_or_cancel_coroutine([handle])
res = self.must_take_notification(handle)
if res is None or serde is None:
if res is None or serde is None or not isinstance(res, bytes):
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about this check. I'd need to review this in depth, can you please revert this check back for now?

Copy link
Contributor Author

@ouatu-ro ouatu-ro Mar 24, 2025

Choose a reason for hiding this comment

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

Currently the function runs serde.deserialize on any object, I made it so it runs deserialisation only on bytes. will rewrite it to this for clarity:

            if res is None or serde is None:
                return res
            if isinstance(res, bytes):
                return serde.deserialize(res)
            return res

Let me know if you want it changed back, but I think it would be a bug? must_take_notification should never return a JSON, it should only return str, list[str], bytes, None.

Copy link
Contributor

@igalshilman igalshilman left a comment

Choose a reason for hiding this comment

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

Thanks!

@igalshilman igalshilman merged commit fae1926 into restatedev:main Mar 24, 2025
4 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 24, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants