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

Wrong type hint of DOMNode.watch method #1805

Closed
mzebrak opened this issue Feb 15, 2023 · 5 comments · Fixed by #1831 or #1929
Closed

Wrong type hint of DOMNode.watch method #1805

mzebrak opened this issue Feb 15, 2023 · 5 comments · Fixed by #1831 or #1929

Comments

@mzebrak
Copy link

mzebrak commented Feb 15, 2023

It looks like after the latest changes 0.11.0 (because in 0.10.1 there was no issue), the wrong type hint was used for DOMNode.watch method.

After upgrading textual in my project I see mypy errorrs like below:

Argument 3 to "watch" of "DOMNode" has incompatible type "Callable[[Any], None]"; expected "Union[Callable[[], Awaitable[None]], Callable[[], None]]"  [arg-type]

After some investigation, argument no.3 in the 0.11.0 is:

callback: CallbackType,

which is:

CallbackType = Union[Callable[[], Awaitable[None]], Callable[[], None]]

This is not true because Callabe can take additional arguments - current_value and previous_value (both of the Any type).

Previously, in the reactive.watch method, it was:

 callback: Callable[[Any], object]
@github-actions
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@github-actions
Copy link

github-actions bot commented Mar 1, 2023

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@mzebrak
Copy link
Author

mzebrak commented Mar 3, 2023

@willmcgugan This one is not fixed in 0.13.0 so shouldn't be closed.

@github-actions
Copy link

github-actions bot commented Mar 3, 2023

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

@mzebrak
Copy link
Author

mzebrak commented Mar 10, 2023

@willmcgugan
0.14.0 fixed most of the errors, but there is still one minor issue:

error: Argument "callback" to "watch" of "DOMNode" has incompatible type "Callable[[], None]"; expected "Union[Callable[[Any], Awaitable[None]], Callable[[Any], None]]"  [arg-type]

It shows up when I attach callback method without any params:

self.watch(self.app, "something", callback=self.__sync_cart_items)

def __sync_cart_items(self) -> None:
    pass

I have to apply workaround such as:

self.watch(self.app, "something", callback=self.__sync_cart_items)

def __sync_cart_items(self, _: Something) -> None:
    pass

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 a pull request may close this issue.

2 participants