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

ItemAdapter.get_field_names_from_class #64

Merged
merged 2 commits into from Aug 2, 2022
Merged

Conversation

kmike
Copy link
Member

@kmike kmike commented Aug 1, 2022

hey! This PR adds a new ItemAdapter classmethod: get_field_names_from_class - similar to get_field_names, but accepts item class, not an item itself. It's motivated by scrapinghub/web-poet#53 (comment).

@codecov
Copy link

codecov bot commented Aug 1, 2022

Codecov Report

Merging #64 (074d9e7) into master (927ee25) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master       #64   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         4           
  Lines          291       318   +27     
=========================================
+ Hits           291       318   +27     
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.

@@ -43,10 +43,13 @@ def test_module_import_error(self):
from itemadapter.adapter import DataclassAdapter

self.assertFalse(DataclassAdapter.is_item(DataClassItem(name="asdf", value=1234)))
with self.assertRaises(RuntimeError, msg="attr module is not available"):
with self.assertRaises(RuntimeError, msg="dataclasses module is not available"):
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure why it's been passing. Probably, assertRaises doesn't work as intended here.

Copy link
Member

Choose a reason for hiding this comment

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

I believe that is the message that shows if the assert fails. We can use assertRaisesRegex if the goal is for the assert of fail if the exception message does not match this one.

kmike referenced this pull request in scrapinghub/web-poet Aug 2, 2022
Copy link
Member

@Gallaecio Gallaecio left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link
Member

@elacuesta elacuesta left a comment

Choose a reason for hiding this comment

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

Looks good @kmike, thanks! Should I release now with this or is there anything else you need?

@elacuesta elacuesta merged commit 900ae14 into master Aug 2, 2022
@elacuesta elacuesta deleted the get-fields-from-class branch August 2, 2022 16:58
@kmike
Copy link
Member Author

kmike commented Aug 2, 2022

Thanks for merging it @elacuesta!
Yes, a release would be perfect; I don't have anything else in mind.

@elacuesta
Copy link
Member

Released https://github.com/scrapy/itemadapter/releases/tag/v0.7.0

@kmike
Copy link
Member Author

kmike commented Aug 2, 2022

Awesome, thanks @elacuesta!

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.

None yet

3 participants