Closed zigai closed 1 month ago
@zigai Thanks for opening the issue. It's interesting because I also use Pylance v2024.7.1 and haven't encountered this problem.
Additionally, I believe the __all__
field is intended just for "star imports" statements, such as:
from crawlee.http_crawler import *
am I correct?
Because the statement Pylance tells you isn't true. HttpCrawler
is exported, and can be imported directly:
from crawlee.http_crawler import HttpCrawler
Pylance type checking mode has to be turned on to see these warnings. It's set to "off" by default, which may be why you don't see them.
The warnings pylance shows aren't true, all imports work correctly on the Python level, but beacuse pylance has problems seeing the actual structure of the module, the user experience for using crawlee inside VS Code is not as good as it could be:
reportPrivateImportUsage
warnings.HttpCrawler
, HttpCrawlingContext
and HttpCrawlingResult
.It's true that the __all__
field is meant for star imports in Python, but some other tools use it for different purposes like determining the public API of a package, which exaplainds why adding it fixes both the warnings and code completion.
If you are able to replicate these problems keep in mind that this solution is more of a workaround, pylance should work without __all__
being defined. This might actually be a problem with how the package is being built.
Yeah tried __all__
seems working.
When using VS Code, pylance (v2024.7.1, latest) frequently reports![image](https://github.com/apify/crawlee-python/assets/69588680/86e756a9-e165-4647-ac6c-f8a921820d55)
reportPrivateImportUsage
errors when importing classes.These errors can be fixed by defining a
__all__
list in the module's__init__.py
file, which explicitly declares the public names for the module.Here's an example for the
http_crawler
module: