-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Annotated[Item, PickFields("x", "y")]
to decide which fields to populate in callback
#111
base: master
Are you sure you want to change the base?
Conversation
There's still some stuff to do but I think this is ready for review to check if we're happy with the API before proceeding any further. from typing Annotated, Optional
import attrs
import scrapy
from scrapy_poet import ItemPage, PickFields, handle_urls, field
@attrs.define
class BigItem:
x: str
y: Optional[str] = None
@handle_urls("example.com")
@attrs.define
class BigPage(ItemPage[BigItem]):
@field
def x(self) -> str:
return "x"
@field
def y(self) -> str:
return "y"
class SomeSpider(scrapy.Spider):
name = "somespider"
def start_requests(self):
yield scrapy.Request("https://example.com", self.parse_item)
def parse_item(self, response, item: Annotated[BigItem, PickFields("x")]): #👈
yield item # should return BigItem(x="x", y=None) |
The API looks good to me. I think |
bc6acb6
to
3c6fdae
Compare
Pausing this as we've decided to move most of the functionalities into web-poet. See scrapinghub/web-poet#115. |
A continuation for #88.
Stemming from the idea in scrapinghub/web-poet#77 to use
typing.Annotated
. See PEP 593.TODO:
NotPickFields
Annotated[PickFields("x", "y"), NotPickFields("y", "z")]
?silent? warning?raisesValueError
PickField/NotPickField
is not available in POAnnotated
in different Python versionsWhen we're happy with the API: