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

Clean render return type #4264

Merged
merged 6 commits into from
Mar 6, 2024
Merged

Conversation

davep
Copy link
Contributor

@davep davep commented Mar 6, 2024

This PR tweaks the type hinting for the render methods of various widgets, to ensure they follow the same hinting as is used in our documentation; the aim being to make the code a little less surprising to the reader and also to ensure that any type hint information shown in an IDE, or auto-completed when inheriting from a Textual widget and overriding the render method, matches what would be expected.

Fixes #4063.

davep added 2 commits March 6, 2024 10:24
Use the type hint that is talked about in the documentation.

Fixes Textualize#4063.
@davep davep added enhancement New feature or request Task labels Mar 6, 2024
@davep davep self-assigned this Mar 6, 2024
@davep davep marked this pull request as ready for review March 6, 2024 14:40
Copy link
Contributor

@rodrigogiraoserrao rodrigogiraoserrao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this “simple” PR, I can't help but feel like you spent a lot of time making sure you were getting all of the instances and to make sure you don't mix the app and Rich's RenderResult 😬

)
from rich.console import RenderResult as RichRenderResult
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these two imports separated from the other rich.console imports?
Why not the suggestion I show below?

from rich.console import (
    Console,
    ConsoleOptions,
    ConsoleRenderable,
    JustifyMethod,
    RenderableType,
    RenderResult as RichRenderResult,
    RichCast,
)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let you have that argument with black and/or whatever else it is that rewrote my code from that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I understand 🤣

src/textual/widgets/_input.py Outdated Show resolved Hide resolved
@davep
Copy link
Contributor Author

davep commented Mar 6, 2024

Looking at this “simple” PR, I can't help but feel like you spent a lot of time making sure you were getting all of the instances and to make sure you don't mix the app and Rich's RenderResult 😬

Yup, that was fun. As I worked through this too I also got to thinking that, in retrospect, it might have been nicer if RenderResult and ComposeResult originated in textual.types too. Possibly. Maybe. Perhaps.

Co-authored-by: Rodrigo Girão Serrão <[email protected]>
@davep davep merged commit f7d6dc8 into Textualize:main Mar 6, 2024
20 checks passed
@davep davep deleted the clean-render-return-type branch March 6, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tidy the return type of App.render
2 participants