scrapy / scrapy

@@ -15,4 +15,4 @@
Loading
15 15
16 16
17 17
def request_to_dict(request: "scrapy.Request", spider: Optional["scrapy.Spider"] = None) -> dict:
18 -
    return request.to_dict(spider)
18 +
    return request.to_dict(spider=spider)

@@ -68,7 +68,7 @@
Loading
68 68
            return cls(crawler, key)
69 69
70 70
        def push(self, request):
71 -
            request = request.to_dict(self.spider)
71 +
            request = request.to_dict(spider=self.spider)
72 72
            return super().push(request)
73 73
74 74
        def pop(self):

@@ -16,7 +16,7 @@
Loading
16 16
17 17
class JsonRequest(Request):
18 18
19 -
    _attributes: Tuple[str, ...] = Request._attributes + ("dumps_kwargs",)
19 +
    attributes: Tuple[str, ...] = Request.attributes + ("dumps_kwargs",)
20 20
21 21
    def __init__(self, *args, **kwargs):
22 22
        dumps_kwargs = copy.deepcopy(kwargs.pop('dumps_kwargs', {}))

@@ -110,13 +110,13 @@
Loading
110 110
111 111
112 112
def request_from_dict(d: dict, spider: Optional[Spider] = None) -> Request:
113 -
    """Create Request object from a dict.
113 +
    """Create a :class:`~scrapy.Request` object from a dict.
114 114
115 115
    If a spider is given, it will try to resolve the callbacks looking at the
116 116
    spider for methods with the same name.
117 117
    """
118 118
    request_cls = load_object(d["_class"]) if "_class" in d else Request
119 -
    kwargs = {key: value for key, value in d.items() if key in request_cls._attributes}
119 +
    kwargs = {key: value for key, value in d.items() if key in request_cls.attributes}
120 120
    if d.get("callback") and spider:
121 121
        kwargs["callback"] = _get_method(spider, d["callback"])
122 122
    if d.get("errback") and spider:

@@ -20,7 +20,7 @@
Loading
20 20
21 21
class Request(object_ref):
22 22
23 -
    _attributes: Tuple[str, ...] = (
23 +
    attributes: Tuple[str, ...] = (
24 24
        "url", "method", "headers", "body", "cookies", "meta", "flags",
25 25
        "encoding", "priority", "dont_filter", "callback", "errback", "cb_kwargs",
26 26
    )
@@ -109,7 +109,7 @@
Loading
109 109
110 110
    def replace(self, *args, **kwargs):
111 111
        """Create a new Request with the same attributes except for those given new values"""
112 -
        for x in self._attributes:
112 +
        for x in self.attributes:
113 113
            kwargs.setdefault(x, getattr(self, x))
114 114
        cls = kwargs.pop('cls', self.__class__)
115 115
        return cls(*args, **kwargs)
@@ -147,10 +147,10 @@
Loading
147 147
        request_kwargs.update(kwargs)
148 148
        return cls(**request_kwargs)
149 149
150 -
    def to_dict(self, spider: Optional["scrapy.Spider"] = None) -> dict:
150 +
    def to_dict(self, *, spider: Optional["scrapy.Spider"] = None) -> dict:
151 151
        """Return a dictionary containing the Request's data.
152 152
153 -
        Use ``scrapy.utils.request.request_from_dict`` to convert back into a full Request object.
153 +
        Use :func:`~scrapy.utils.request.request_from_dict` to convert back into a :class:`~scrapy.Request` object.
154 154
155 155
        If a spider is given, this method will try to find out the name of the spider method used
156 156
        as callback and include it in the output dict, raising an exception if it cannot be found.
@@ -161,7 +161,7 @@
Loading
161 161
            "errback": _find_method(spider, self.errback) if callable(self.errback) else self.errback,
162 162
            "headers": dict(self.headers),
163 163
        }
164 -
        for attr in self._attributes:
164 +
        for attr in self.attributes:
165 165
            d.setdefault(attr, getattr(self, attr))
166 166
        if type(self) is not Request:
167 167
            d["_class"] = self.__module__ + '.' + self.__class__.__name__
Files Coverage
scrapy 88.12%
Project Totals (162 files) 88.12%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading