Alternative to `__all__`
Although typecheckers don't complain about the lack of `__all__` within the package itself (hence why I failed to catch this initially, sorry!), they do complain about it when one imports a typed package into their own. That means when I use torf in my own library like `from torf import Torrent` type checkers complain that `Torrent` is an unknown attribute and they bail out (essentially making the stubs useless). This has two work arounds:
1. Define `__all__` in both `__init__.pyi` and `__init__.py` to explicitly tell typecheckers and IDEs what torf exports
2. Change `from ._torrent import Torrent` to `from ._torrent import Torrent as Torrent` in `__init__.pyi` (`__init__.py` can be left untouched). This relies on the fact that `X as X` is a heuristic that typecheckers use to determine if the package wants to export `X` as a part of the public API
关闭于 2024-10-26 1 条评论