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

Multiple itemadapter classes #68

Merged
merged 6 commits into from
Mar 29, 2023
Merged

Multiple itemadapter classes #68

merged 6 commits into from
Mar 29, 2023

Conversation

elacuesta
Copy link
Member

@elacuesta elacuesta commented Feb 24, 2023

No description provided.

@codecov
Copy link

codecov bot commented Feb 24, 2023

Codecov Report

Merging #68 (5ffd681) into master (0bf9f0c) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 5ffd681 differs from pull request most recent head 5882f43. Consider uploading reports for the commit 5882f43 to get more accurate results

@@            Coverage Diff            @@
##            master       #68   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          318       323    +5     
=========================================
+ Hits           318       323    +5     
Impacted Files Coverage Δ
itemadapter/adapter.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Comment on lines 376 to 379
if isinstance(obj, ItemAdapter):
return obj.asdict()
if ItemAdapter.is_item(obj):
return ItemAdapter(obj).asdict()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why keeping this would be needed.

Copy link
Member Author

@elacuesta elacuesta Feb 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a rare case, but we need to convert nested objects to dicts even if the ItemAdapter subclass itself does not handle them: 2732297

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to convert nested objects to dicts even if the ItemAdapter subclass itself does not handle them

Why do we need to do this? I'd expect that if a subclass e.g. removed support for dataclasses, that's on purpose, and user wants an exception to be raised. If user wants dataclasses support, it's easy to add it back explicitly.

Copy link
Member

@kmike kmike Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the issue could be that in the examples we don't show how to reuse the default set of adapters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, removed the lines in question. Regarding the example, that would just be inheriting from the ItemaAdapter class and not overriding the ADAPTER_CLASSES attributes, how would you phrase that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elacuesta I mean that in the examples you want to add an adapter to the existing adapter classes - this is essentially what was examples showing. But now it's a bit more complicated, because you need to use add something to the list from the base class. I'm fine with proceeding without these examples :)

@elacuesta elacuesta marked this pull request as ready for review February 26, 2023 16:38
@wRAR
Copy link
Member

wRAR commented Feb 28, 2023

How would one use this feature, e.g. in the scrapinghub/web-poet#136 case? I think we need to be able to set the adapter list to use in web-poet when it generates and runs tests, and the actual contents of the list need to be user-defined?

@kmike what do you think?

@kmike
Copy link
Member

kmike commented Feb 28, 2023

How would one use this feature, e.g. in the scrapinghub/web-poet#136 case? I think we need to be able to set the adapter list to use in web-poet when it generates and runs tests, and the actual contents of the list need to be user-defined?

@wRAR This makes sense. It can also be a path to ItemAdapter class (or the class itself), not sure what's better.

@wRAR
Copy link
Member

wRAR commented Feb 28, 2023

Are we sure it will be possible to provide some interface in web-poet to use this? I guess we could make some setting for the class list and create the subclass inside the web-poet code based on it. Asking the user to create the subclass is probably more work for the user.

@kmike kmike merged commit 07f6f6c into master Mar 29, 2023
@elacuesta elacuesta deleted the multiple-itemadapter-classes branch March 31, 2023 01:08
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

Successfully merging this pull request may close these issues.

4 participants