Skip to content

Commit

Permalink
Merge pull request scrapy#6147 from wRAR/crawler-init-docs
Browse files Browse the repository at this point in the history
Improve the docs about Crawler attributes and settings initialization.
  • Loading branch information
wRAR committed Nov 16, 2023
2 parents 492584e + 603aa49 commit 42b3a3a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ Backward-incompatible changes
:meth:`scrapy.crawler.Crawler.__init__` and before the settings are
finalized and frozen. This change was needed to allow changing the settings
in :meth:`scrapy.Spider.from_crawler`. If you want to access the final
setting values in the spider code as early as possible you can do this in
:meth:`~scrapy.Spider.start_requests`. (:issue:`6038`)
setting values and the initialized :class:`~scrapy.crawler.Crawler`
attributes in the spider code as early as possible you can do this in
:meth:`~scrapy.Spider.start_requests` or in a handler of the
:signal:`engine_started` signal. (:issue:`6038`)

- The :meth:`TextResponse.json <scrapy.http.TextResponse.json>` method now
requires the response to be in a valid JSON encoding (UTF-8, UTF-16, or
Expand Down
10 changes: 8 additions & 2 deletions docs/topics/spiders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,14 @@ scrapy.Spider
method, which is handy if you want to modify them based on
arguments. As a consequence, these settings aren't the final values
as they can be modified later by e.g. :ref:`add-ons
<topics-addons>`. The final settings are available in the
:meth:`start_requests` method and later.
<topics-addons>`. For the same reason, most of the
:class:`~scrapy.crawler.Crawler` attributes aren't initialized at
this point.

The final settings and the initialized
:class:`~scrapy.crawler.Crawler` attributes are available in the
:meth:`start_requests` method, handlers of the
:signal:`engine_started` signal and later.

:param crawler: crawler to which the spider will be bound
:type crawler: :class:`~scrapy.crawler.Crawler` instance
Expand Down

0 comments on commit 42b3a3a

Please sign in to comment.