Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.2k
Support constraint application forBase64Etc
types#10584
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
cloudflare-workers-and-pagesbot commentedOct 9, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Deploying pydantic-docs with |
Latest commit: | 8b4f35d |
Status: | ✅ Deploy successful! |
Preview URL: | https://e998034b.pydantic-docs.pages.dev |
Branch Preview URL: | https://bytes-fix.pydantic-docs.pages.dev |
codspeed-hqbot commentedOct 9, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
CodSpeed Performance ReportMerging#10584 willnot alter performanceComparing Summary
|
@@ -2580,7 +2593,7 @@ def decode_str(self, data: bytes, _: core_schema.ValidationInfo) -> str: | |||
Returns: | |||
The decoded data. | |||
""" | |||
return data.decode() | |||
returnself.encoder.decode(data.encode()).decode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
So that I understand the intent here - we validate astr
, thenencode
->bytes
,decode
with ourencoder
, thendecode
back to astr
? 🤮
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
yeah, since the encoder operates on bytes I think you need to do this if you want to apply it to strings
Coverage reportClick to see where and how coverage changed
This report was generated bypython-coverage-comment-action |
I think this is the right behavior, but if we have any issues with this type in v2.10, this would be the PR to revisit. Seems pretty low stakes, though... |
76222d2
intomainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Alternative to#10500
Fixes#9251
Had to decouple (though, I view this as a sort of simplification) the
EncodedBytes
andEncodedStr
dataclases. The API here feels a bit confusing- having theencoder
separate from these types that define the pydantic methods seems overly complex.Additionally, the
EncodedStr
type (unless I'm misunderstanding) does quite a large amount of encoding and decoding for both validation and serialization...The main fix here is using
handler(source)
as the schema for the validator functions so that any constraints applied to the original type are respected.