From 9b696835941f41062574032ba8c5f583c408adca Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 27 Jun 2021 12:31:28 -0700 Subject: [PATCH 1/4] Recommend `Self` in CONTRIBUTING.md Part of #5676. --- CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3e02a66931e1..91b05a03d92c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -337,6 +337,9 @@ Some further tips for good type hints: possible type, and `Text` if it can be either `unicode` or `bytes`; * use platform checks like `if sys.platform == 'win32'` to denote platform-dependent APIs. +* `__enter__` methods and other methods that return instances of the + current class should be annotated with the `_typeshed.Self` type + variable ([example](https://github.com/python/typeshed/pull/5689)). Imports in stubs are considered private (not part of the exported API) unless: From fc4746c120c9d7d6083c712ff97d9d4ae79e48fb Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 27 Jun 2021 12:49:33 -0700 Subject: [PATCH 2/4] put it next to `__exit__` guidelines --- CONTRIBUTING.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 91b05a03d92c..0b228d57c275 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -337,9 +337,6 @@ Some further tips for good type hints: possible type, and `Text` if it can be either `unicode` or `bytes`; * use platform checks like `if sys.platform == 'win32'` to denote platform-dependent APIs. -* `__enter__` methods and other methods that return instances of the - current class should be annotated with the `_typeshed.Self` type - variable ([example](https://github.com/python/typeshed/pull/5689)). Imports in stubs are considered private (not part of the exported API) unless: @@ -375,6 +372,9 @@ have the return type be either `None` or `Optional[bool]`. If you are not sure whether exceptions are suppressed or not or if the context manager is meant to be subclassed, pick `Optional[bool]`. See https://github.com/python/mypy/issues/7214 for more details. +`__enter__` methods and other methods that return instances of the +current class should be annotated with the `_typeshed.Self` type +variable ([example](https://github.com/python/typeshed/pull/5689)). A few guidelines for protocol names below. In cases that don't fall into any of those categories, use your best judgement. From d4f857eb68669034d1deb489a06a48a08fd7abd9 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 27 Jun 2021 22:54:37 +0300 Subject: [PATCH 3/4] change example pr Co-authored-by: Jelle Zijlstra --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0b228d57c275..b47f1ff8032e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -374,7 +374,7 @@ context manager is meant to be subclassed, pick `Optional[bool]`. See https://github.com/python/mypy/issues/7214 for more details. `__enter__` methods and other methods that return instances of the current class should be annotated with the `_typeshed.Self` type -variable ([example](https://github.com/python/typeshed/pull/5689)). +variable ([example](https://github.com/python/typeshed/pull/5698)). A few guidelines for protocol names below. In cases that don't fall into any of those categories, use your best judgement. From 52221eddb90a724c9b36d72d74babba9abc1c2d8 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 27 Jun 2021 13:00:20 -0700 Subject: [PATCH 4/4] blank line --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b47f1ff8032e..7a0a31c7c67a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -372,6 +372,7 @@ have the return type be either `None` or `Optional[bool]`. If you are not sure whether exceptions are suppressed or not or if the context manager is meant to be subclassed, pick `Optional[bool]`. See https://github.com/python/mypy/issues/7214 for more details. + `__enter__` methods and other methods that return instances of the current class should be annotated with the `_typeshed.Self` type variable ([example](https://github.com/python/typeshed/pull/5698)).