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

Fix strict parsing for some Sequences #8614

Merged
merged 3 commits into from Jan 25, 2024
Merged

Conversation

sydney-runkle
Copy link
Member

@sydney-runkle sydney-runkle commented Jan 23, 2024

Change Summary

Handle this case properly, right now, it errors:

from typing import Sequence

from pydantic import TypeAdapter

assert TypeAdapter(Sequence[int]).validate_python((), strict=True) == ()

Related issue number

Fix #8604

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Selected Reviewer: @lig

Copy link

cloudflare-pages bot commented Jan 23, 2024

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: e655b92
Status: ✅  Deploy successful!
Preview URL: https://93cfa7fd.pydantic-docs2.pages.dev
Branch Preview URL: https://fix-list-strict-validation.pydantic-docs2.pages.dev

View logs

@sydney-runkle sydney-runkle added the relnotes-fix Used for bugfixes. label Jan 23, 2024
Copy link

codspeed-hq bot commented Jan 23, 2024

CodSpeed Performance Report

Merging #8614 will not alter performance

Comparing fix-list-strict-validation (e655b92) with main (3e87125)

Summary

✅ 10 untouched benchmarks

Comment on lines +39 to +41
if value_type == tuple:
__input_value = list(__input_value)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is certainly not the most performant, but we already warn about the performance consequences of using Sequence[X] in the docs, so I'm ok with this change for now, assuming we implement the refactor for sequence validators in the future.

@sydney-runkle
Copy link
Member Author

Please review

@sydney-runkle sydney-runkle enabled auto-merge (squash) January 25, 2024 16:36
@sydney-runkle sydney-runkle merged commit d67eff2 into main Jan 25, 2024
53 of 55 checks passed
@sydney-runkle sydney-runkle deleted the fix-list-strict-validation branch January 25, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strict mode rejects valid types
2 participants