You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I spent so long banging my head against the wall, and I feel like a clarification in the docs could help others.
In all the tutorials, you import a variable called 'main' but never actually use the variable. I thought it was weird, so I just removed the import. After many hours, I realized that it is very necessary to import main...
I have never seen an API that requires importing a variable but not using the variable. In fact, most linters will say this is an error. I think because of this non-standard API choice, the tutorials should warn people that 'main' MUST be imported for apps to be served properly.
The text was updated successfully, but these errors were encountered:
Thanks for reporting @spencerchubb! The main is being imported so that we can hack around Uvicorn requiring if __name__ == main as an entry point. If you are familiar with marker interface, this is very similar and can be called a "marker import".
While I agree the unused import is non-standard, it's the best we can do. Any PR that could make it better is more than welcome.
Meanwhile, do you have any suggestions on where this should be included in the docs to save time and prevent head injuries from banging against the wall? :)
# Note: main must be imported even though it is not used
from h2o_wave import main, app, Q, ui
@app('/foo')
async def serve(q: Q):
# Modify the page
q.page['qux'] = ui.some_card()
# Save the page
await q.page.save()
I spent so long banging my head against the wall, and I feel like a clarification in the docs could help others.
In all the tutorials, you import a variable called 'main' but never actually use the variable. I thought it was weird, so I just removed the import. After many hours, I realized that it is very necessary to import main...
I have never seen an API that requires importing a variable but not using the variable. In fact, most linters will say this is an error. I think because of this non-standard API choice, the tutorials should warn people that 'main' MUST be imported for apps to be served properly.
The text was updated successfully, but these errors were encountered: