posit-dev / posit-dev/py-shiny
Should have simple way to declare types of input vars
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 135
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 21
Description
Currently it's possible to declare the types of input values like this:
class MyInputs(Inputs):
txt: reactive.Value[str]
go: reactive.Value[int]
def server(input: Inputs, output: Outputs, session: Session):
input = cast(MyInputs, input)
...
But it would be nice to be able to do something like this:
class MyInputs(Inputs):
txt: str
go: int
Notes:
- Some inputs (like those from dynamic UI) will have a possible value of
None - This should inform Python that both
input.txtandinput["txt"]are of typereactive.Value[str].
I think it should be possible to do these things. TypedDict, for example, does some complex stuff with types:
https://github.com/python/cpython/blob/bd8b05395ad8877f4a065562444e117b1650c022/Lib/typing.py#L2381-L2438
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the Inputs type and reactive.Value definitions referenced in the issue, then trace how attribute and mapping access are typed. The change is complete when annotations such as txt: str and go: int expose reactive.Value[str] and reactive.Value[int] for both access forms, including possible None values for dynamic inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100