From 69e258970ed7956f700c869a5f9234ca9ff5fde9 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sat, 14 Aug 2021 12:15:00 +0200 Subject: [PATCH 1/4] Use PEP 604 syntax Built-in generics not possible in type aliases --- CONTRIBUTING.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 00da3ca96f16..c2fff85b244f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -327,9 +327,10 @@ checker, and leave out unnecessary detail: Some further tips for good type hints: * use built-in generics (`list`, `dict`, `tuple`, `set`), instead - of importing them from `typing`, **except** for arbitrary length tuples - (`Tuple[int, ...]`) (see - [python/mypy#9980](https://github.com/python/mypy/issues/9980)); + of importing them from `typing`, **except** in type aliases and for + arbitrary length tuples (`Tuple[int, ...]`); +* use `X | Y` instead of `Union[X, Y]` and `X | None`, instead of + `Optional[X]`, **except** in type aliases; * in Python 3 stubs, import collections (`Mapping`, `Iterable`, etc.) from `collections.abc` instead of `typing`; * avoid invariant collection types (`list`, `dict`) in argument From 237bd64d1051dd84ba0f848d98658166473c4d41 Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sat, 14 Aug 2021 14:04:47 +0200 Subject: [PATCH 2/4] class bases --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c2fff85b244f..849f683f75a4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -330,7 +330,7 @@ Some further tips for good type hints: of importing them from `typing`, **except** in type aliases and for arbitrary length tuples (`Tuple[int, ...]`); * use `X | Y` instead of `Union[X, Y]` and `X | None`, instead of - `Optional[X]`, **except** in type aliases; + `Optional[X]`, **except** in type aliases and class bases; * in Python 3 stubs, import collections (`Mapping`, `Iterable`, etc.) from `collections.abc` instead of `typing`; * avoid invariant collection types (`list`, `dict`) in argument From b752f77e9c3a45883d001d19ed583ed31a36e0bc Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sat, 14 Aug 2021 20:41:24 +0200 Subject: [PATCH 3/4] Update CONTRIBUTING.md Co-authored-by: Akuli --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 849f683f75a4..efa065cdc2db 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -330,7 +330,7 @@ Some further tips for good type hints: of importing them from `typing`, **except** in type aliases and for arbitrary length tuples (`Tuple[int, ...]`); * use `X | Y` instead of `Union[X, Y]` and `X | None`, instead of - `Optional[X]`, **except** in type aliases and class bases; + `Optional[X]`, **except** when it is not possible due to mypy bugs (type aliases and base classes); * in Python 3 stubs, import collections (`Mapping`, `Iterable`, etc.) from `collections.abc` instead of `typing`; * avoid invariant collection types (`list`, `dict`) in argument From de1ec815a1034c0c649f3691a45535ef0cef9c4d Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Sat, 14 Aug 2021 22:07:33 +0200 Subject: [PATCH 4/4] Update CONTRIBUTING.md Co-authored-by: Akuli --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index efa065cdc2db..981bdbb81f1d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -327,7 +327,7 @@ checker, and leave out unnecessary detail: Some further tips for good type hints: * use built-in generics (`list`, `dict`, `tuple`, `set`), instead - of importing them from `typing`, **except** in type aliases and for + of importing them from `typing`, **except** in type aliases, in base classes, and for arbitrary length tuples (`Tuple[int, ...]`); * use `X | Y` instead of `Union[X, Y]` and `X | None`, instead of `Optional[X]`, **except** when it is not possible due to mypy bugs (type aliases and base classes);