KEMBAR78
Fix strict parsing for some `Sequence`s by sydney-runkle · Pull Request #8614 · pydantic/pydantic · GitHub
Skip to content

Conversation

@sydney-runkle
Copy link
Contributor

@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

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-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
@codspeed-hq
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
Contributor 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
Contributor Author

Please review

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