Skip to content
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

Merged
merged 4 commits into from
Jun 1, 2023

Conversation

Kludex
Copy link
Member

@Kludex Kludex commented Jun 1, 2023

Selected Reviewer: @samuelcolvin

@cloudflare-pages
Copy link

cloudflare-pages bot commented Jun 1, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6b64a6d
Status: ✅  Deploy successful!
Preview URL: https://7d6f1141.pydantic-docs2.pages.dev
Branch Preview URL: https://tests-coverage-on-json-schem-onrl.pydantic-docs2.pages.dev

View logs

Comment on lines -870 to -871
except IndexError as e:
raise ValueError('Cannot generate a JsonSchema for a zero-step ChainSchema') from e
Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert what?

Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like that, yes.

Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

@lig lig Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We are eliminating a separate logic branch that is introduced by try..except
  2. We explicitly express our knowledge that there couldn't be an empty collection here
  3. 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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment 👍

Copy link
Member Author

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. 🤔

@Kludex Kludex marked this pull request as ready for review June 1, 2023 11:58
@Kludex
Copy link
Member Author

Kludex commented Jun 1, 2023

please review

Copy link
Contributor

@lig lig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@Kludex
Copy link
Member Author

Kludex commented Jun 1, 2023

Gracias 🙏

@Kludex Kludex merged commit d850234 into main Jun 1, 2023
53 checks passed
@Kludex Kludex deleted the tests/coverage-on-json-schema-part-2 branch June 1, 2023 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants