Skip to content

Commit

Permalink
Merge branch 'feature/enhance-445-optional-model' of github.com:Mityu…
Browse files Browse the repository at this point in the history
…ha/polyfactory into feature/enhance-445-optional-model
  • Loading branch information
Mityuha committed Dec 9, 2023
2 parents 6f6c7b0 + 9a86dac commit 8586074
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"

Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:

- name: Set up python ${{ matrix.python-version }}
id: checkout-python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down Expand Up @@ -101,7 +101,7 @@ jobs:
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Check out repository
uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"

Expand All @@ -40,7 +40,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"

Expand Down
8 changes: 5 additions & 3 deletions polyfactory/factories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def create_factory(
)

@classmethod
def get_constrained_field_value(cls, annotation: Any, field_meta: FieldMeta) -> Any: # noqa: C901, PLR0911
def get_constrained_field_value(cls, annotation: Any, field_meta: FieldMeta) -> Any: # noqa: C901, PLR0911, PLR0912
try:
constraints = cast("Constraints", field_meta.constraints)
if is_safe_subclass(annotation, float):
Expand Down Expand Up @@ -564,16 +564,18 @@ def get_constrained_field_value(cls, annotation: Any, field_meta: FieldMeta) ->
pattern=constraints.get("pattern"),
)

with suppress(ValueError):
try:
collection_type = get_collection_type(annotation)
except ValueError:
collection_type = None
if collection_type is not None:
if collection_type == dict:
return handle_constrained_mapping(
factory=cls,
field_meta=field_meta,
min_items=constraints.get("min_length"),
max_items=constraints.get("max_length"),
)

return handle_constrained_collection(
collection_type=collection_type, # type: ignore[type-var]
factory=cls,
Expand Down

0 comments on commit 8586074

Please sign in to comment.