posit-dev / posit-dev/py-shiny
Improve error messages for context managers called functionally
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 135
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 21
Description
Users who see existing documentation or examples using shiny.ui.card() may try the following app structure
from shiny.express import ui
a_card = ui.card("A simple card")
but this will fail with a TypeError
[...snip...]
File "/Users/garrick/work/posit-dev/py-shiny/shiny/express/app.py", line 14, in __getattr__
return wrap_express_app(Path(name))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/garrick/work/posit-dev/py-shiny/shiny/express/_run.py", line 42, in wrap_express_app
app_ui = run_express(file).tagify()
^^^^^^^^^^^^^^^^^
File "/Users/garrick/work/posit-dev/py-shiny/shiny/express/_run.py", line 98, in run_express
exec(
File "/Users/garrick/work/posit-dev/py-shiny/shiny/api-examples/layout_column_wrap/app-express.py", line 3, in <module>
a_card = ui.card("A simple card")
^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: card() takes 0 positional arguments but 1 was given
This generic error is not very helpful for new users and does not provide actionable advice. Ideally, we'd instruct users to switch to the context manager form, possibly with an error like the following:
`card()` was called with positional arguments, but in Shiny Express `card()`
does not take unnamed arguments. Please use the `with ui.card():` form instead.
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 reproducing the shown ui.card("A simple card") example, then inspect shiny/express/app.py and shiny/express/_run.py, which appear in the traceback. Done means the functional call produces actionable guidance to use the context-manager form instead of only the generic TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100