Skip to content

Add ready: bool annotation to YRoom #126

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

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/pycrdt/websocket/yroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class YRoom:
ydoc: Doc
ystore: BaseYStore | None
ready_event: Event
ready: bool
_on_message: Callable[[bytes], Awaitable[bool] | bool] | None
_update_send_stream: MemoryObjectSendStream
_update_receive_stream: MemoryObjectReceiveStream
Expand Down Expand Up @@ -83,7 +84,7 @@ def __init__(
"""
self.ydoc = Doc() if ydoc is None else ydoc
self.ready_event = Event()
self.ready = ready
self.ready: bool = ready
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe really add the annotation at the class level above, as your comment says?

Copy link
Author

Choose a reason for hiding this comment

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

That change caused a mypy error in the CI, likely because we already have a @property defined for it. You can check the details here

Copy link
Author

Choose a reason for hiding this comment

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

The property and setter are already properly annotated as returning/taking bool, so I’m not sure why mypy is still complaining about this. To work around this, I think it’s simplest to add a class-level annotation and silence the redefinition error with a # type: ignore.

self.ystore = ystore
self.log = log or getLogger(__name__)
self.awareness = Awareness(self.ydoc)
Expand All @@ -106,7 +107,7 @@ def started(self):
self._started = Event()
return self._started

@property
@property # type: ignore[no-redef]
def ready(self) -> bool:
"""
Returns:
Expand Down
Loading