widgetti / solara

A Pure Python, React-style Framework for Scaling Your Jupyter and Web Apps
https://solara.dev
MIT License
1.84k stars 135 forks source link

pyright complain "component" is not exported from module "solara" #465

Open zhuoqiang opened 8 months ago

zhuoqiang commented 8 months ago

pyright complains "component" is not exported from module "solara" for the following code, line 3

import solara

@solara.component
class Page
    pass

turns out it is not a false alarm, see https://github.com/microsoft/pyright/issues/5929

By default, all imports in a py.typed library are considered private unless they are explicitly re-exported. To indicate that an imported symbol is intended to be re-exported, the maintainers of this library would need to use one of the techniques documented here

so I guess instead of

from reacton import component

it could be updated to re-exported using the redundant form to make pyright happy

from reacton import component as component
Lundez commented 7 months ago

I think adding the following to .vscode/settings.json solved this for me 👍

    "python.analysis.packageIndexDepths": [
        {
            "name": "",
            "depth": 5
        }
    ],
Jhsmit commented 6 months ago

I have the same issue (with pylance) Not only solara.component but also solara.use_state (basically any reacton import)

unfortunately @Lundez' fix doesnt seem to help

adding __all__ to __init__.py can also fix the issue

edan-bainglass commented 1 month ago

@Jhsmit true, an explicit __all__ would help! For now, to calm pylance, I replace solara imports with more specific (deep) ones.

from solara.core import component

@component
def MyComponent():
    ...

A bit more work, but acceptable at least in my use case. There are TODO tags regarding __all__ in the solara module, so hopefully coming soon :)