From 3baf0873cc3db0bc54f195b461a07bc889ce8609 Mon Sep 17 00:00:00 2001 From: ftnext Date: Sun, 13 Oct 2024 22:50:42 +0900 Subject: [PATCH] [docs] Show rationale --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index b6469d3..07d2135 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,17 @@ Use abstract types instead of concrete ones | KTH102 | Use `Iterable` or `Sequence` instead of `tuple` | | KTH103 | Use `Iterable` instead of `set` | | KTH104 | Use `Iterable` instead of `dict` | + +## Rationale + +https://docs.python.org/ja/3/library/typing.html#typing.List + +>Note that to annotate arguments, it is preferred to use an abstract collection type such as `Sequence` or `Iterable` rather than to use `list` or `typing.List`. + +https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#standard-duck-types + +>Use Iterable for generic iterables (anything usable in "`for`"), and Sequence where a sequence (supporting "`len`" and "`__getitem__`") is required + +https://typing.readthedocs.io/en/latest/reference/best_practices.html#arguments-and-return-types + +>For arguments, prefer protocols and abstract types (`Mapping`, `Sequence`, `Iterable`, etc.).