textual icon indicating copy to clipboard operation
textual copied to clipboard

Tidy the return type of `App.render`

Open davep opened this issue 2 years ago • 2 comments

Currently the return type of App.render is RenderableType; in our docs and in most places we talk about App.render returning a RenderResult. RenderResult is an alias for RenderableType and is a top-level value in textual.app.

This can cause a lint/type warning in dev's apps if they let their IDE complete the signature when writing their own render method, as it will often complete to something like this:

    def render(self) -> RenderableType:
        return super().render()

which in turn will auto-import RenderableType from textual.app. This can then result in a warning like this:

Screenshot 2024-01-23 at 14 16 46

We should change App.render so that it's typed as returning RenderResult rather than RenderableType, then such completion will use the type that is exported from textual.app.

Also note that the code in the compose/render HOWTO seems to have fallen foul of this and has that type warning.

davep avatar Jan 23 '24 14:01 davep

This seems a simple enough fix that I could help (if wanted!). But I can't seem reproduce this in my editor, so I just wanted to check where you've seen/tested this?

[EDIT: I'm assuming certainly in VSCode from other instances I found. I've gone ahead with a PR but needs a double-check that this is indeed the fix!]

TomJGooding avatar Jan 24 '24 21:01 TomJGooding

But I can't seem reproduce this in my editor, so I just wanted to check where you've seen/tested this?

In my case Emacs+eglot+pyright while auto-completing def render.

davep avatar Jan 25 '24 09:01 davep

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

github-actions[bot] avatar Mar 06 '24 18:03 github-actions[bot]