-
Notifications
You must be signed in to change notification settings - Fork 32
♻️ Maintenance: Updates on new Annotated type style and llm-prompts
#7749
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
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #7749 +/- ##
==========================================
+ Coverage 87.31% 88.94% +1.63%
==========================================
Files 1838 1458 -380
Lines 71454 60515 -10939
Branches 1214 474 -740
==========================================
- Hits 62392 53828 -8564
+ Misses 8720 6566 -2154
+ Partials 342 121 -221
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Annotated type style and toolsAnnotated type style and llm-prompts
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.
Pull Request Overview
This PR refactors existing custom string types to the new Pydantic v2 Annotated/StringConstraints style (including introducing SafeQueryStr), updates all related usage in the API and tests, and adds guidance in docs/llm-prompts for migrating Pydantic fields to the Annotated pattern.
- Refactors basic_types to
Annotated[str, StringConstraints]and adds_SHORT_TRUNCATED_STR_MAX_LENGTH,_LONG_TRUNCATED_STR_MAX_LENGTH, andSafeQueryStr - Updates API dependencies and test suites to use the new types and constants
- Adds a new
docs/llm-prompts/pydantic-annotated-fields.mdwith migration prompts
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| services/api-server/src/.../models_schemas_solvers_filters.py | Switched query parameters from str to SafeQueryStr |
| packages/models-library/tests/test_projects.py | Updated project patch test to use _LONG_TRUNCATED_STR_MAX_LENGTH |
| packages/models-library/tests/test_basic_types.py | Revised ShortTruncatedStr tests to use _SHORT_TRUNCATED_STR_MAX_LENGTH and added more scenarios |
| packages/models-library/src/models_library/rabbitmq_basic_types.py | Replaced RPCMethodName subclass with an Annotated type alias |
| packages/models-library/src/models_library/projects.py | Converted ProjectIDStr to an Annotated type alias |
| packages/models-library/src/models_library/basic_types.py | Migrated constrained string classes to Annotated style and added new constants and SafeQueryStr |
| docs/llm-prompts/pydantic-annotated-fields.md | New prompt document for migrating Pydantic Field() to Annotated |
Comments suppressed due to low confidence (4)
packages/models-library/src/models_library/projects.py:45
AnnotatedandTypeAliasare used here but neither is imported in this file; addfrom typing import Annotated, TypeAliasto avoid a NameError.
ProjectIDStr: TypeAlias = Annotated[str, StringConstraints(pattern=UUID_RE_BASE)]
packages/models-library/tests/test_basic_types.py:80
- [nitpick] This test imports and relies on a private constant (
_SHORT_TRUNCATED_STR_MAX_LENGTH); consider exposing a public constant or API for max length to avoid depending on an internal name.
curtail_length = _SHORT_TRUNCATED_STR_MAX_LENGTH
packages/models-library/tests/test_projects.py:11
- [nitpick] Test is importing and using a private constant (
_LONG_TRUNCATED_STR_MAX_LENGTH); consider providing a public API or constant for this value to keep tests from breaking on internal renames.
from models_library.basic_types import _LONG_TRUNCATED_STR_MAX_LENGTH
docs/llm-prompts/pydantic-annotated-fields.md:3
- [nitpick] The prompt examples assume the user will import
Annotatedfromtypingbut don't explicitly instruct it; consider adding "Addfrom typing import Annotated" to ensure completeness.
Please convert all pydantic model fields that use `Field()` with default values to use the Annotated pattern instead.
bisgaard-itis
left 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.
thanks. just a small suggestion
sanderegg
left 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.
Thanks ! I just missed an example where you replaced the deprecated idstring
…otated and StringConstraints
…aints and trim_string_before
…string length and whitespace handling
…rsion_display parameters
|



What do these changes do?
Updated old types into using new pydantic validators pipelines using
Annotatedtypesmodels_library.basic_typeAnnotated[str, Val1, ...]which validates without affecting the actual python typeSafeQueryStrto use e.g. query parameters of string filters (after PR review with @wvangeit )pydantic-annotated-fields.md: should assist upgrading pydantic classes using the old style.Related issue/s
How to test
Dev-ops