Textualize / textual

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.
https://textual.textualize.io/
MIT License
24.99k stars 764 forks source link

[typing] Inconsistent typing in the work decorator #3510

Open rodrigogiraoserrao opened 11 months ago

rodrigogiraoserrao commented 11 months ago

See this discussion about the usage of Decorator versus Decorator[..., ReturnType] in src/textual/_work_decorator.py.

EDIT: Last time I tackled this (and opened PR #3862) I ended up hitting what looked like a mypy issue but might as well just be something I didn't get right. I did try to outsource the fix to Twitter and a Discord server but no one was able to help me. Independently from me, PR #3937 does similar work that would also fix this issue.

willmcgugan commented 9 months ago

@rodrigogiraoserrao I'm assuming this is a quick fix?

rodrigogiraoserrao commented 9 months ago

Depends. When it comes to typing, what do we use as the ground truth? mypy, pylance, or another typechecker?

willmcgugan commented 9 months ago

Ideally we can get them to agree. If not, Mypy.

rodrigogiraoserrao commented 9 months ago

I was exploring a fix to the typing issues that then triggered new typing issues in other places of the codebase where the decorator work is used.

Work on this surfaced a possible mypy bug. I've created a standalone gist which seems to contain this possible bug: https://mypy-play.net/?mypy=latest&python=3.12&gist=c451dedbb5ec867b98fcfec6aa24d698 I also asked for help on Twitter: https://twitter.com/mathsppblog/status/1734247854854599035