Closed tongl2 closed 4 weeks ago
Directly setting self.dark to False will raise a type-check lint:
Dark should be Reactive
as it is a reactive. Moreover, setting dark
to False
has the desired effect with this code:
from textual.app import App, ComposeResult
from textual.widgets import Label
class LightApp(App[None]):
def __init__(self):
super().__init__()
self.dark = False
def compose(self) -> ComposeResult:
yield Label("This is a light app")
if __name__ == "__main__":
LightApp().run()
I also see no type issues with the code (in this case using pyright):
It might be a good idea to say what you're using for type checking, and perhaps which IDE you're using. For example, the type checker in (some versions of?) PyCharm are known to be lacking a little and sometimes can mislead people.
Yeah, PyCharm doesn't understand descriptors all that well. @Haphaistos2333 feel free to report this to the PyCharm folks.
Don't forget to star the repository!
Follow @textualizeio for Textual updates.
Current code in src/textual/app.py:
I personally believe the type of the attribute "dark" should be bool instead of Reactive. (Correct me if I was wrong.)
Reactive class does not implement
__bool__
method, soReactive(False)
is actuallyTrue
when casted to bool, which is quite confusing. In the code example, the first execution ofself.app.dark = not self.app.dark
is actually settingself.app.dark
to boolean typeFalse
, which mean if I initially setself.app.dark
toReactive(False)
, the theme is still light unless I toggle it once. The code seems not using features of Reactive on dark attribute, so it will be more convincing changing the type to bool.