-
Notifications
You must be signed in to change notification settings - Fork 575
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
Improve handling of GroupedMetadata #3986
Improve handling of GroupedMetadata #3986
Conversation
elif getattr(arg, "__is_annotated_types_grouped_metadata__", False): | ||
for subarg in arg: | ||
if getattr(subarg, "__is_annotated_types_grouped_metadata__", False): | ||
yield from _get_constraints(tuple(subarg)) |
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.
Just for my understanding: is this addition (supporting nested grouped metadata) related to pydantic/pydantic#4682 (comment), or is it just something you added as an enhancement?
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.
Unrelated bugfix, really.
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.
For the needs of the Pydantic plugin, this looks good! thx
Sorry I misread some bits of the PR, I'm just a bit worried about defining an
@_dataclasses.dataclass(**_internal_dataclass.slots_true)
class UuidVersion(annotated_types.GroupedMetadata):
"""A field metadata class to indicate a [UUID](https://docs.python.org/3/library/uuid.html) version."""
uuid_version: Literal[1, 3, 4, 5]
def __get_pydantic_json_schema__(
self, core_schema: core_schema.CoreSchema, handler: GetJsonSchemaHandler
) -> JsonSchemaValue:
...
def __get_pydantic_core_schema__(self, source: Any, handler: GetCoreSchemaHandler) -> core_schema.CoreSchema:
...
def __iter__(self):
if "hypothesis" in sys.modules:
yield some_strategy
else:
# What to do? Raise an error? However, it seems pretty common to have this pattern, e.g. defining I'll start the implementation on the Pydantic side, and see if they are ok with it! |
The readme types it as So actually I have two followups:
|
Ah yes sorry was looking at the actual type definition indeed! |
I'm partner dvir478 is working on issue #3986 |
I am Esra-Al and working on issue #3986 |
Fixes #3980, closes #3981.
Motivated by pydantic/pydantic#4682 (comment); supporting nested-
GroupedMetadata
and short-circuiting if such an item contains anst.SearchStrategy
will allow for extensive control purely from downstream code.