Preconfigured union for a "plain" python data structures

オープン
#554 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
data

調査の方向性

Review the existing preconfigured converters and PythonConverter configuration to identify the entry point for adding another preset. Use the proposed plain Python passthrough types and collection overrides as the acceptance criteria, then verify that the new converter preserves those values and collections during conversion.

索引モデルが issue の本文から書いたものです。

説明

There are preconfigured converters for the various serialization formats, but I have found need for a converter specific to what I will call "plain" Python.

Basically:

PassThroughTypes: TypeAlias = str | bool | int | float | bytes | None

def python_make_converter(
    *args: Any,
    **kwargs: Any,
) -> PythonConverter:

    # configure specific overrides for this converter
    kwargs["unstruct_collection_overrides"] = {
        # rich built-in types are maintained, rather than all dumped
        # into lists
        Sequence: tuple,
        MutableSequence: list,
        Set: frozenset,
        MutableSet: set,
        Counter: lambda c: Counter(**{k: v for k, v in c}),
    }

    converter = PythonConverter(*args, **kwargs)

    # passthrough union types
    configure_union_passthrough(PassThroughTypes, converter)

    return converter

Just some context for what I am doing that warranted making this concrete versus the more plain cattrs.global_converter. I am using the converter to generate "patches" that all happens within Python and the above to be very useful.

I would propose that a new preconfigured converter be made similar to the others. But I can understand it not being high priority, in which case this issue may help someone else :)

主要言語
Python
スター
1.1k
フォーク
159
平均マージ
12時間 21分
マージ済み PR(30日)
6

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-attrs/cattrs のほかの issue

python-attrs/cattrs の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。