Typing error on panel.state.notifications.error based on examples
wilsonnater opened this issue · comments
This feel like a bug, documentation issue, or implementation issue, but is probably a relatively low priority. The current way panel.state.notification is typed means the example uses of notifications will give an error from typing checking. (If it returned None, then calling error on it would fail). It appears to be originating at this line of code https://github.com/holoviz/panel/blob/main/panel/io/state.py#L1044
ALL software version info
panel 1.2.3
mypy 0.971
mypy-extensions 0.4.3
Description of expected behavior and the observed behavior
Mypy gives this error error: Item "None" of "Optional[NotificationArea]" has no attribute "error"
on pn.state.notifications.error('This is an error notification.', duration=1000)
Complete, minimal, self-contained example code that reproduces the issue
import panel as pn
pn.extension("notifications")
pn.state.notifications.error('This is an error notification.', duration=1000)
Stack traceback and/or browser JavaScript console output
Screenshots or screencasts of the bug in action
- [ x ] I may be interested in making a pull request to address this
For anyone else reading this, a quick work around is checking if the notification is None.
notification = pn.state.notifications
if notification is not None:
notifications.error('This is an error notification.', duration=1000)
This seems like it is connected or related to some other issues with notifications. #6184