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 the un-hashability of various annotation types, for use in caching generic containers #6480
Conversation
Deploying with Cloudflare Pages
|
Hmm thought about this a bit more and I think it might be better to not add |
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.
Note: I'm trying to get in the habit of reviewing more code here. Apologies if my comments are n00b.
Code looks straightforward overall. I appreciate the addition of tests. Your PR description mentions inclusion of methods in caching, though I don't see any tests which relate to the caching of these methods. (Unless they are implicit?)
tests/test_types.py
Outdated
ValidateStrAsInt = Annotated[str, TransformSchema(lambda _s: core_schema.int_schema())] | ||
|
||
class Model(BaseModel): | ||
x: Optional[ValidateStrAsInt] | ||
|
||
assert Model(x=None).x is None | ||
assert Model(x='1').x == 1 |
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.
Transformation from a string repr of an int/float/decimal is no longer automatically executed in V2, right? I'm assuming you are overriding this with TransformSchema(lambda _s: core_schema.int_schema())
?
Also, this test could be rewritten as parameterized if you wanted to go overboard. Perhaps some other edge cases like negative numbers, or floats? (Though would a float get transformed to an int?)
5b8c801
to
206dceb
Compare
206dceb
to
fee40b4
Compare
|
please review |
skip change file check
Selected Reviewer: @hramezani