From a35252eefd32a039ad726db4a1965db74e08ee27 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 20 Jul 2021 14:11:05 +0100 Subject: [PATCH] backport _typeshed.Self --- contextlib2/__init__.pyi | 2 +- contextlib2/_typeshed.py | 5 +++++ dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch | 9 ++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 contextlib2/_typeshed.py diff --git a/contextlib2/__init__.pyi b/contextlib2/__init__.pyi index 4549200..30ab561 100644 --- a/contextlib2/__init__.pyi +++ b/contextlib2/__init__.pyi @@ -2,7 +2,7 @@ # https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE import sys -from _typeshed import Self +from ._typeshed import Self from types import TracebackType from typing import ( IO, diff --git a/contextlib2/_typeshed.py b/contextlib2/_typeshed.py new file mode 100644 index 0000000..f05558d --- /dev/null +++ b/contextlib2/_typeshed.py @@ -0,0 +1,5 @@ +from typing import TypeVar + +# Use for "self" annotations: +# def __enter__(self: Self) -> Self: ... +Self = TypeVar("Self") diff --git a/dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch b/dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch index 65a3e35..31d9882 100644 --- a/dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch +++ b/dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch @@ -1,12 +1,15 @@ --- ../contextlib.pyi 2021-07-16 08:26:16.409945194 +0100 -+++ contextlib2/__init__.pyi 2021-07-16 08:32:00.363150171 +0100 -@@ -1,3 +1,6 @@ ++++ contextlib2/__init__.pyi 2021-07-20 14:10:49.571136279 +0100 +@@ -1,5 +1,8 @@ +# Type hints copied from the typeshed project under the Apache License 2.0 +# https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE + import sys - from _typeshed import Self +-from _typeshed import Self ++from ._typeshed import Self from types import TracebackType + from typing import ( + IO, @@ -17,8 +20,14 @@ ) from typing_extensions import ParamSpec, Protocol