-
Notifications
You must be signed in to change notification settings - Fork 727
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
ListView
type hints
#3599
base: main
Are you sure you want to change the base?
ListView
type hints
#3599
Conversation
Hi @fkaab, thanks for your PR. What is the problem that your PR solves? If you hit a problem while using Textual, it is always a good idea to start by opening an issue so that everyone is made aware of the problem you are facing and so that we can discuss possible solutions. Thanks! |
Hello @rodrigogiraoserrao,
or similarly subclass ListView
As of now this is highlighted as erroneous in my IDE. The PR changes that. Also I have now fixed most of the issues highlighted by the typecheck. |
@rodrigogiraoserrao If it helps, check the type hints and completions in your editor, when this PR is your active Textual: from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Button, ListView, ListItem, ProgressBar
class ProgressItem(ListItem):
def compose(self) -> ComposeResult:
yield ProgressBar()
class FunList(ListView[ProgressItem]):
pass
class VariedLVApp(App[None]):
def compose(self) -> ComposeResult:
yield Button("More fun")
yield FunList(
ProgressItem(),
ProgressItem(),
ProgressItem(),
ProgressItem(),
ProgressItem(),
)
@on(Button.Pressed)
def more_fun(self) -> None:
self.query_one(FunList).append(ProgressItem())
if __name__ == "__main__":
VariedLVApp().run() I did have a look into this once before, albeit more concentrating on typing I did have a concern about how useful and viable it was when it came to message handlers with multiple Since then we've also added |
I have played around with your example for a bit @davep, and everything seems to work fine. There are three things I would like to note:
On an unrelated note: I am not really a professional software developer and was kind of unaware of the make tool used in this project and its capabilities. I suggest adding a line to the contribution guidelines about running the typecheck when one introduces new type hints or new classes. |
Thanks @fkaab. I think I'm struggling to follow/envisage what you're referring to in your first point, do you think you could further illustrate it for me in some way? The second point, I think, sounds like a more general bug in As for the third point: yeah, that seems very out of scope for what's going on in this PR. Good point on helping people discover the |
@davep @rodrigogiraoserrao This seems reasonable to me. What do you guys think? |
@willmcgugan I think I remember it looking like a good approach, but it's like 5 months since. |
Ditto. |
Added type hints for the type of
ListItem
contained in aListView
.