-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add support for field processors. #85
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #85 +/- ##
=======================================
Coverage 99.81% 99.81%
=======================================
Files 17 17
Lines 536 553 +17
=======================================
+ Hits 535 552 +17
Misses 1 1
|
The implementation and tests makes sense to me, thanks @wRAR! Could you please add docs for this feature? it should be a section in https://github.com/scrapinghub/web-poet/blob/master/docs/advanced/fields.rst |
There is also a note in the current docs, which says
I think we should remove it, and actually explain that having preprocessing logic in items may be problematic. This new docs section would be a good place for it. |
I've added a docs section.
Why would it be problematic? |
It breaks the following (from the docs):
If field processing happens in the item, it means you can't use page_object.field instead of item.field, the result would be wrong (i.e. without cleaning). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good @wRAR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Co-authored-by: Adrián Chaves <[email protected]>
After re-reading zytedata/zyte-common-items#18 I realized that typing could be an issue. But it turns out proper typing is not implemented for |
This adds support for an
out=
argument to@field
, as proposed in zytedata/zyte-common-items#18 (option 3). It only supports a list of callables, though it should be easy to also add support for a single callable. It only supports synchronous processors as async processors don't seem too useful and would change the signature of the field from sync to async which I find problematic.I'm not sure how idiomatic (wrt both Python and web-poet) is the implementation but it's simple enough to be able to adjust it.