Open wRAR opened 10 months ago
I wonder if we can register DummyResponse as a Response subclass. Or maybe we should have a sepatate type for annotation in Scrapy itself, to communicate what is the interface of the Response which the callbacks can expect, if it's not the Response.
DummyResponse is a Response subclass but you cannot narrow argument types in subclasses.
Annotated[Response, "dummy"]
? :slightly_smiling_face:
scrapy.Spider.parse
has aResponse
type hint for theresponse
argument, and custom callbacks may also have hints forresponse
and for some kwargs, and then in subclasses the callback with the same name can have different hints for the same arguments. In the simplest case it's justresponse: DummyResponse
.All of these violate the Liskov substitution principle and mypy will produce errors for the overridden callbacks. This should already happen when the base class is user-defined and will also happen for any
parse()
with e.g.response: DummyResponse
after Scrapy withpy.typed
is released.I don't currently have any suggestions for resolving this.