Adding Type Hints to Scrapy and its Modules
See original GitHub issueSummary
We should add Variable Annotations/ Type hints as supported in PEP 526 , Python 3.6 to Scrapy to help out existing and new contributors and developers in understanding scrapy code.
Motivation
Intellisense enabled IDES like PyCharm need Type hints to provide better experience. For new contributors to understand Scrapy comprehensively, type hints are vital.
Consider someone not that familiar with scrapy, stumbling upon scheduler’s constructor.
def __init__(self, dupefilter, jobdir=None, dqclass=None, mqclass=None,
logunser=False, stats=None, pqclass=None, crawler=None):
self.df = dupefilter
self.dqdir = self._dqdir(jobdir)
self.pqclass = pqclass
self.dqclass = dqclass
self.mqclass = mqclass
self.logunser = logunser
self.stats = stats
self.crawler = crawler
Issue Analytics
- State:
- Created 4 years ago
- Reactions:9
- Comments:20 (11 by maintainers)
Top Results From Across the Web
Scrapy Tutorial — Scrapy 2.7.1 documentation
Scrapy Tutorial¶. In this tutorial, we'll assume that Scrapy is already installed on your system. If that's not the case, see Installation ...
Read more >Settings — Scrapy 2.7.1 documentation
The Scrapy settings allows you to customize the behaviour of all Scrapy components, including the core, extensions, pipelines and spiders ...
Read more >Common Practices — Scrapy 2.7.1 documentation
Common Practices¶. This section documents common practices when using Scrapy. These are things that cover many topics and don't often fall into any...
Read more >Items — Scrapy 2.7.1 documentation
Scrapy supports the following types of items, via the itemadapter library: dictionaries, Item objects, dataclass objects, and attrs objects.
Read more >Installation guide — Scrapy 2.7.1 documentation
Scrapy requires Python 3.7+, either the CPython implementation (default) or the PyPy implementation (see Alternate Implementations). Installing ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well I think pydantic would be useful if type hints could be added to scrapy in future versions. It could help validate types, also make it easier to read configuration files and environment variables. After adding these settings, the code will be easier to understand. For example,
Item
can be defined as subclasses ofpydantic.BaseModel
, making it more convenient to use, and settings can be defined as subclasses ofpydantic.BaseSettings
I have tested MonkeyType, and get the following conclusions:
from __future__ import annotations
automaticallyIt seems Monkeytype can help for typing hint in some way, but manually checking the result is still necessary.