litestar-org/polyfactory

Enhancement: Support non-mutable Mapping containers

Aperta

#726 aperta il 3 lug 2025

 (1 commento) (2 reazioni) (0 assegnatari)Python (114 fork)auto 404
enhancementgood first issue

Metriche repository

Star
 (1491 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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

Guida contributor