Skip to content

Conversation

sydney-runkle
Copy link
Contributor

@sydney-runkle sydney-runkle commented Jun 10, 2024

Fix #9381

I've been wanting to refactor the logic from #9303 for a while, and this seemed like a good time to do that.

Still working on this, want to generally improve the annotation application.

Selected Reviewer: @adriangb

@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Jun 10, 2024
Copy link

cloudflare-workers-and-pages bot commented Jun 10, 2024

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 37e7348
Status: ✅  Deploy successful!
Preview URL: https://6d944a00.pydantic-docs.pages.dev
Branch Preview URL: https://annotation-application-fix.pydantic-docs.pages.dev

View logs

Copy link

codspeed-hq bot commented Jun 10, 2024

CodSpeed Performance Report

Merging #9623 will not alter performance

Comparing annotation-application-fix (37e7348) with main (d93a046)

Summary

✅ 13 untouched benchmarks

@sydney-runkle
Copy link
Contributor Author

Please review

Comment on lines +190 to +209
COMPARISON_VALIDATORS = {
'gt': _validators.greater_than_validator,
'ge': _validators.greater_than_or_equal_validator,
'lt': _validators.less_than_validator,
'le': _validators.less_than_or_equal_validator,
'multiple_of': _validators.multiple_of_validator,
'min_length': _validators.min_length_validator,
'max_length': _validators.max_length_validator,
}

CONSTRAINT_STR_FROM_ANNOTATED_TYPE = {
at.Gt: 'gt',
at.Ge: 'ge',
at.Lt: 'lt',
at.Le: 'le',
at.MultipleOf: 'multiple_of',
at.MinLen: 'min_length',
at.MaxLen: 'max_length',
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This feels excessive - any better ideas?

Comment on lines +284 to +287
if chain_schema_steps:
chain_schema_steps = [schema] + chain_schema_steps
return cs.chain_schema(chain_schema_steps)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One interesting question here is what happens when you have mixes of constraints that are applied as validator functions vs chain schema additions. This implementation isn't breaking any tests (in fact, fixing bugs), but I could see an argument for considering a pattern for this more carefully.

@sydney-runkle sydney-runkle merged commit 13dc7c3 into main Jun 11, 2024
@sydney-runkle sydney-runkle deleted the annotation-application-fix branch June 11, 2024 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StringConstraints: Bug
2 participants