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

Pydantic v2 support #91

Merged
merged 9 commits into from
Jan 29, 2025
Merged

Conversation

Gallaecio
Copy link
Member

Continuation of #86 with the following additional changes:

  • The itemadapter API remains backward compatible (no separate PydanticV1Adapter class).
  • Add extras for attrs, pydantic and scrapy, so that users can make sure they get the right versions of those packages (and potential future dependencies related to them) when installing them for itemadapter.
  • Create separate tox envs for attrs, pydantic, scrapy, and combining all of them. Test with minimum and latest versions. For Pydantic, also test with the latest 1.x version. The regular tox envs do not install those dependencies.
  • Create a separate docs tox env to check the README code.
  • Updated the README to reflect the output with the latest pydantic version.
  • Replace the README ADAPTER_CLASSES example that requires cloning the repo (uses tests/ code) with one that installs a third-party package instead (zyte-common-items). I think the code is more readable, and it’s good to point to a real example of a custom adapter.

Resolves #72, closes #76, closes #86.

self.assertFalse(PydanticAdapter.is_item(ScrapyItem()))
self.assertFalse(PydanticAdapter.is_item(ScrapySubclassedItem()))

@unittest.skipIf(not PydanticV1Model, "pydantic <2 module is not available")
Copy link
Member

Choose a reason for hiding this comment

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

would it make sense to skip the whole test module if pydantic1 is not available?

Copy link
Member Author

@Gallaecio Gallaecio Jan 29, 2025

Choose a reason for hiding this comment

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

For the record, pydantic1 is always available if pydantic (whatever version) is installed.

It may make sense not to run extra-specific tests if the corresponding extra is not installed. But only if the corresponding adapter is not available in that scenario. It currently is available and I think it makes sense to test its “is_item” implementation in scenarios where the corresponding extra is not installed.

I think it may be best to discuss this in a separate issue or PR, ad we may change the API, and in ny case do the same for all extras.

Copy link
Member

Choose a reason for hiding this comment

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

Should we release this now or do that separate discussion first?

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 fine with either approach.

@Gallaecio Gallaecio merged commit 621b6b2 into scrapy:master Jan 29, 2025
23 checks passed
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.

Pydantic 2 released
6 participants