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

fix: constrained unions #499

Merged
merged 9 commits into from
Mar 2, 2024
Merged

fix: constrained unions #499

merged 9 commits into from
Mar 2, 2024

Conversation

guacs
Copy link
Member

@guacs guacs commented Feb 7, 2024

Description

  • Fix the parsing of the constraints from union types for Pydantic v2 models
    • Before there used to be special handling of optional types, but that's not needed since optional types are also unions and so optional types should also be handled the same way as union types where we just ignore NoneType. This makes the change the same as that of FieldMeta.from_type (as changed in fix: handle unions properly #491).
  • Fix the way the annotated types are handled when calling FieldMeta.from-type by using the actual type that is annotated rather than Annotated[type, ...]
    • Due to the change in FieldMeta.type_args in fix: handle unions properly #491, Annotated[List[str], MinLen(10)] now returns List[str] whereas before it would have returned str as the child. This results in the children for the FieldMeta corresponding to the annotation Annotated[List[str], MinLen(10)] to be List[str] instead of str. Unwrapping the annotation to get the actual underlying type fixes this problem since now FieldMeta.type_args will return str in this case instead of List[str].

Close Issue(s)

@guacs guacs requested review from a team as code owners February 7, 2024 13:06
@guacs guacs changed the title Constrained unions fix: constrained unions Feb 7, 2024
Copy link

sonarcloud bot commented Mar 2, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
91.7% Coverage on New Code (required ≥ 98%)

See analysis details on SonarCloud

Copy link

github-actions bot commented Mar 2, 2024

Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/499

@guacs
Copy link
Member Author

guacs commented Mar 2, 2024

I think the sonar code coverage issue can be ignored since the missing coverage is for the 3.8 specific code.

@guacs guacs merged commit 0f8f9e8 into main Mar 2, 2024
21 of 22 checks passed
@guacs guacs deleted the constrained-unions branch March 2, 2024 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Optional constrained types do not work
2 participants