Fix getting annotations for _parse_sitemap() at the runtime. (#6671)

* Fix getting annotations for _parse_sitemap() at the runtime.

* Split off the callback annotations test.
This commit is contained in:
Andrey Rakhmatullin 2025-02-14 19:40:06 +04:00 committed by GitHub
parent 00167edca0
commit 7d5b189c11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View File

@ -2,6 +2,9 @@ from __future__ import annotations
import logging
import re
# Iterable is needed at the run time for the SitemapSpider._parse_sitemap() annotation
from collections.abc import Iterable, Sequence # noqa: TC003
from typing import TYPE_CHECKING, Any, cast
from scrapy.http import Request, Response, XmlResponse
@ -11,8 +14,6 @@ from scrapy.utils.gz import gunzip, gzip_magic_number
from scrapy.utils.sitemap import Sitemap, sitemap_urls_from_robots
if TYPE_CHECKING:
from collections.abc import Iterable, Sequence
# typing.Self requires Python 3.11
from typing_extensions import Self

20
tests/test_poet.py Normal file
View File

@ -0,0 +1,20 @@
"""Tests that make sure parts needed for the scrapy-poet stack work."""
from typing import get_type_hints
from scrapy import Spider
from scrapy.spiders import CrawlSpider, CSVFeedSpider, SitemapSpider, XMLFeedSpider
def test_callbacks():
"""Making sure annotations on all non-abstract callbacks can be resolved."""
for cb in [
Spider._parse,
CrawlSpider._parse,
CrawlSpider._callback,
XMLFeedSpider._parse,
CSVFeedSpider._parse,
SitemapSpider._parse_sitemap,
]:
get_type_hints(cb)