Add fixes for type stub generation #828
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When shiny type stubs are generated by pyright, and they are used for types (instead of using the shiny source code directly), we have some typing errors, which are visible in shinylive:
This is because some of the .pyi files generated by pyright lack necessary type information. This PR fixes most cases of missing types in the .pyi files, but not all.
@schloerke in the future we should have an automated test which runs pyright on the generated .pyi files, as well as the examples (but using the shiny type stubs instead of shiny sources directly).
To illustrate what's going on, here's the relevant part of
OutputTransformer
from _transformer.py before the change:This is the content of the resulting _transformer.pyi file:
Notice that it loses all information about
self._fn
,self.ValueFn
,self.OutputRenderer
, andself.OutputRendererDecorator
.This is what the
OutputTransformer
looks like after the change:The class-level variables like
fn
andOutputRenderer
aren't actually used by any of the code, but pyright uses them for generating type stubs. This is the resulting _transformer.pyi file:That change makes the red underlines go away in shinylive.