Wrong annotations in scrapy.crawler.CrawlProcess.crawl docstrings
See original GitHub issueDescription
Some IDEs recognize type annotations within docstring to make suggestions or raise warnings related to your code. In the Scrapy source, there are some annotations in the docstring that are wrong.
[Description of the issue]
This is a minor issue. The scrapy.crawler.CrawlerProcess.crawl
method expects one mandatory positional argument, crawler_or_spidercls
, and optional positional and keyword arguments through arbitrary argument lists. The type annotations for the arbitrary argument lists are wrong:
https://github.com/scrapy/scrapy/blob/3989f64baa39f7e42b0f798dec15cd250e0fba21/scrapy/crawler.py#L183-L185
When using list
for args
and dict
for kwargs
, the docstring suggests that the types of arguments passed through these lists should be list
and dict
respectively. According to PEP 484, the types of args
and kwargs
will be automatically deduced as Tuple[list, ...]
and Dict[dict, int]
, so the specified types correspond to the values they contain. These annotations don’t match the intention you have with this method, do they? BTW, list
and dict
weren’t generic types for annotations until Python 3.9.
Versions
Scrapy : 2.3.0
lxml : 4.5.2.0
libxml2 : 2.9.10
cssselect : 1.1.0
parsel : 1.6.0
w3lib : 1.22.0
Twisted : 20.3.0
Python : 3.8.5 | packaged by conda-forge | (default, Sep 16 2020, 17:43:11) - [Clang 10.0.1 ]
pyOpenSSL : 19.1.0 (OpenSSL 1.1.1g 21 Apr 2020)
cryptography : 3.1
Platform : macOS-10.14.6-x86_64-i386-64bit
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
Makes sense. For the record, we recently added a typing check in the CI process, so annotating the actual function definition is a possibility. Feel free to open a PR if you’d like.
As far as I am aware, I don’t think we need to specify the data types for *args or **kwargs. So, would a fix that completely eliminates the specification of the data types (list and dict) be fine ?