-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Increase coverage for json_schema.py
#5963
Conversation
Deploying with Cloudflare Pages
|
except IndexError as e: | ||
raise ValueError('Cannot generate a JsonSchema for a zero-step ChainSchema') from e |
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.
It's impossible to reach this, because a chain schema will always have more than zero steps. It's being validated on the rust side.
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.
an assert instead of try then?
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.
assert what?
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.
assert len(schema['steps']) > 0
?
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.
Something like that, yes.
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.
Or just assert schema['steps']
it's effectively the same.
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.
what's the goal of adding that assertion?
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.
- We are eliminating a separate logic branch that is introduced by
try..except
- We explicitly express our knowledge that there couldn't be an empty collection here
- We ensure that in case something changed we will get into this assert.
In this particular case it looks like [3] doesn't help much as we will get IndexError anyway.
In terms of [2], the performance degradation isn't significant but it is there.
Maybe just removing try..except
and leaving a comment instead of the assert is enough here.
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.
Added a comment 👍
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 think I didn't push the code with the comment, I'm going to add it on the next PR. 🤔
please review |
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.
👍🏻
Gracias 🙏 |
Selected Reviewer: @samuelcolvin