litestar-org/polyfactory

Enhancement: Support non-mutable Mapping containers

开放

#726 创建于 2025年7月3日

 (1 条评论) (2 个反应) (0 位负责人)Python (114 个派生)auto 404
enhancementgood first issue

仓库指标

星标
 (1,491 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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

贡献者指南