Skip to content
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

Provide item classes directly #23

Open
kmike opened this issue May 30, 2021 · 1 comment
Open

Provide item classes directly #23

kmike opened this issue May 30, 2021 · 1 comment

Comments

@kmike
Copy link
Member

kmike commented May 30, 2021

An idea: allow callbacks to request item classes directly. So, instead of writing one of those:

    def parse_product(self, response: DummyResponse,
                      page: AutoExtractProductPage):
        product = page.to_item()

    def parse_product(self, response: DummyResponse,
                      produuct_data: AutoExtractProductData):
        product = product_data.to_item()

it would be possible to write

    def parse_product(self, response: DummyResponse,
                      product: Product):

Edge cases:

  1. If I'm not mistaken, to_item() might return None. It seems errback should be called in this case.
  2. There can be non-autoextract ways to get Product, so there should be a way to turn it off (or turn it on, depending on what the default we decide on). It could be a separate provider or an option.
@ivanprado
Copy link
Contributor

This is definitely a good idea. Asking for pages to get the items is very confusing and introduce a lot of boilerplate code.

If I'm not mistaken, to_item() might return None. It seems errback should be called in this case.

If we don't allow the None case, then we limit the functionality of this new approach. It wouldn't be entirely the same to use the product instead of the product page. I don't like that. We have to think twice regarding the None case and the error handling in general in the Page Objects model. We might decide to remove the option to return None but introduce some way to raise errors instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants