litestar-org / litestar-org/polyfactory

Enhancement: Support non-mutable Mapping containers

Open
#726 1 comment 2 reactions 0 assignees View on GitHub
enhancement good first issue
Dominant language
Python
Stars
1.5k
Forks
120
PR merge metrics
No merged PRs in 30d

Description

### Summary

Currently [`handle_collection_type`](https://github.com/litestar-org/polyfactory/blob/f270b0fb46f36b32db0a1c9f9d2cea25c59b8f22/polyfactory/value_generators/complex_types.py#L15) only supports `MutableMapping`s, could support for non-mutable `Mapping`s also be added? I am personally trying to use this alongside the `frozendict` pypi package.

### Basic Example

You could make a factory for e.g.
```python
@dataclass
class Shop(frozen=True)
prices: MyImmutableMapping[str, int]
```
where `MyImmutableMapping` is a subclass of [`Mapping`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping). Currently this will raise
```
NotImplementedError: Unsupported container type:
```

### Drawbacks and Impact

Very few drawbacks in my opinion: changes should be small and isolated and adds functionality many users could benefit from.

### Unresolved questions

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in polyfactory/value_generators/complex_types.py at handle_collection_type, where MutableMapping support and the Unsupported container type error are described. Add support for non-mutable Mapping subclasses, then verify that a factory can build the immutable mapping field in the Shop example without raising NotImplementedError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.