polyfactory icon indicating copy to clipboard operation
polyfactory copied to clipboard

Enhancement: Support non-mutable Mapping containers

Open lunik1 opened this issue 6 months ago • 1 comments

Summary

Currently handle_collection_type only supports MutableMappings, could support for non-mutable Mappings 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.

@dataclass
class Shop(frozen=True)
    prices: MyImmutableMapping[str, int]

where MyImmutableMapping is a subclass of Mapping. Currently this will raise

 NotImplementedError: Unsupported container type: <class 'MyImmutableMapping'>

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

lunik1 avatar Jul 03 '25 19:07 lunik1

This seems reasonable to support. PRs welcome to add :)

adhtruong avatar Jul 03 '25 21:07 adhtruong