yukinarit / pyserde

Yet another serialization library on top of dataclasses, inspired by serde-rs.
https://yukinarit.github.io/pyserde/guide/en
MIT License
726 stars 40 forks source link

Translate types.md to Japanese #554

Closed K-dash closed 4 months ago

K-dash commented 4 months ago

Related to https://github.com/yukinarit/pyserde/issues/545

types.mdの日本語版Docを作成しました。

確認と相談

脚注の5(Optional型)のリンクが存在しなかったため、暫定的に脚注6(Union型)のexamples/union.pyへのリンクを差し込みました。 こちら、脚注5(Optional型)のexampleが存在しないのは意図されているものでしょうか? もし意図されていない場合、examplesのunion.py内に以下のような簡単なOptional型の例を追加するのはいかがでしょうか? (OptionalはNoneとのUnionなので、Optionalのexampleを新規に作るのは仰々しいかなと思った次第です)

from serde import serde
from serde.json import from_json, to_json

@serde
class Bar:
    v: int

@serde
class Baz:
    v: float

@serde
class Foo:
    a: int | str
    b: dict[str, int] | list[int]
    c: Bar | Baz
    d: Baz | Bar | None  # Optional

def main() -> None:
    f = Foo(10, [1, 2, 3], Bar(10), None)
    print(f"Into Json: {to_json(f)}")

    s = '{"a": 10, "b": [1, 2, 3], "c": {"Bar": {"v": 10}}}'
    print(f"From Json: {from_json(Foo, s)}")

    f = Foo("foo", {"bar": 1, "baz": 2}, Baz(100.0), Baz(200.0))
    print(f"Into Json: {to_json(f)}")

    s = '{"a": "foo", "b": {"bar": 1, "baz": 2}, "c": {"Baz": {"v": 100.0}}, "d": {"Bar": {"v": 200}}}'
    print(f"From Json: {from_json(Foo, s)}")

if __name__ == "__main__":
    main()

レビューをお願いします 🙏

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 91.04%. Comparing base (ac3c68f) to head (f3576af). Report is 13 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #554 +/- ## ======================================= Coverage 91.04% 91.04% ======================================= Files 13 13 Lines 1942 1942 Branches 437 437 ======================================= Hits 1768 1768 Misses 117 117 Partials 57 57 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

yukinarit commented 4 months ago

examplesのunion.py内に以下のような簡単なOptional型の例を追加するのはいかがでしょうか?

賛成です :raised_hands: