-
Notifications
You must be signed in to change notification settings - Fork 291
Flatten schemas and replace macros with plain code #450
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
Conversation
c34243a
to
7dc5087
Compare
CodSpeed Performance ReportMerging #450 Summary
Benchmarks breakdown
|
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #450 +/- ##
==========================================
- Coverage 95.36% 94.90% -0.46%
==========================================
Files 93 93
Lines 11115 11157 +42
Branches 22 22
==========================================
- Hits 10600 10589 -11
- Misses 510 563 +53
Partials 5 5
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
1b2c0c5
to
20837c2
Compare
src/validators/mod.rs
Outdated
// The left hand side of this match is a 1:1 match with the `type` field we use as a discriminator | ||
// in our CoreSchema union | ||
// The right hand side is _generally_ a 1:1 match but there are cases where we use a `Builder` | ||
// on the right that may have internal logic to return different validators or just build a | ||
// a more complex validator (e.g. building a union of isinstance validators or something). | ||
// So to get from Python -> Rust implementation you should trace the `type` on the left hand side | ||
// of the match and then if the right hand side is a `{Type}Validator` you've found the implementation. | ||
// If the right hand side is a `{Type}Builder` you'll have to look into it's `build()` method to see | ||
// what it actually returns. | ||
// TODO: sort alphabetically? By left hand side string or right hand side type? Or RHS type's module filename? |
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.
@dmontagu comment as per discussion earlier today
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.
the flattening looks good.
I really don't agree above removing the macos, sorry.
Cargo.toml
Outdated
@@ -1,4 +1,5 @@ | |||
[package] | |||
rust-version = "1.59" |
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.
humm, I'm not sure about this, is there a specific version to pin this?
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.
Sorry again this is accidental. In trying to debug with that segfault I updated to 1.70 which seems to be totally broken
rust-toolchain
Outdated
@@ -1 +1 @@ | |||
nightly | |||
nightly-2023-03-01 |
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.
I'd rather not pin this.
Probably better to remove this file completely.
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.
Sorry this was accidental and unrelated to this PR.
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.
the file is now gone which should make things easier.
src/serializers/shared.rs
Outdated
$($e_key($e_serializer),)* | ||
$($b_key($b_serializer),)* | ||
} | ||
#[derive(Debug, Clone)] |
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.
sorry 😄
I don't agree about removing this macro, it's working, it removes duplication, happy to add a better docstring.
I'd really rather we didn't remove it.
@@ -40,7 +40,8 @@ impl BuildSerializer for FunctionBuilder { | |||
build_context: &mut BuildContext<CombinedSerializer>, | |||
) -> PyResult<CombinedSerializer> { | |||
let py = schema.py(); | |||
let mode: &str = schema.get_as_req(intern!(py, "mode"))?; | |||
let type_: &str = schema.get_as_req(intern!(py, "type"))?; | |||
let mode = type_.split_once('-').unwrap().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.
neat.
@@ -39,7 +22,7 @@ pub struct TupleVariableSerializer { | |||
} | |||
|
|||
impl TupleVariableSerializer { | |||
fn build( | |||
pub fn build( |
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.
this should become an implementation of the BuildSerializer
trait.
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.
Okay yes we can do that.
@@ -160,7 +143,7 @@ pub struct TuplePositionalSerializer { | |||
} | |||
|
|||
impl TuplePositionalSerializer { | |||
fn build( | |||
pub fn build( |
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.
same.
src/validators/mod.rs
Outdated
} | ||
|
||
// macro to build the match statement for validator selection | ||
macro_rules! validator_match { |
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.
again, I'd rather keep this macro.
src/validators/mod.rs
Outdated
let schema: &PyDict = schema.downcast()?; | ||
let type_: &str = schema.get_as_req(intern!(schema.py(), "type"))?; | ||
let val = match type_ { | ||
// The left hand side of this match is a 1:1 match with the `type` field we use as a discriminator |
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.
this comment is great, in general, please add it before the macro.
src/validators/mod.rs
Outdated
// of the match and then if the right hand side is a `{Type}Validator` you've found the implementation. | ||
// If the right hand side is a `{Type}Builder` you'll have to look into it's `build()` method to see | ||
// what it actually returns. | ||
// TODO: sort alphabetically? By left hand side string or right hand side type? Or RHS type's module filename? |
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.
Not sure i agree about alphabetical, in theory validators are ordered logically in core_schema.py
, then the order here should ideally match that.
If we make a change, we should make it everywhere.
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.
Whatever we do, it would be nice to find a consistent order. But we may have to pick between the order in core_schema.py
and the order of the implementations in src/validators/*.rs
. But let's leave this as a not indicating that there is no order currently and we can loop back to determining and implementing an order in the future.
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.
agreed, it should be consistent.
alphabetic is obviously simplest. problem is it puts closes related validators like model
and typed-dict
or int
and float
far apart.
One isn't really possible without the other. The macros assume a 1:1 mapping between the Besides:
|
I think it is, you would just need a 1:1 mapping between I'm strongly of the opinion that having the |
362d62d
to
5c0d11b
Compare
please review I added back the macros. I do see the point about duplicating strings, it makes sense. I think a macro that just expands the match statement is helpful, but maybe we can simplify the serializer macro by manually writing the enum? I think I’ll add back the comments (updated) tomorrow if this hasn’t been merged yet (otherwise another PR) |
5c0d11b
to
894e90c
Compare
Closes #444