From f620a31c790141a011043fa8cd767aba38af36db Mon Sep 17 00:00:00 2001 From: adriengcql Date: Tue, 13 Jan 2026 18:02:53 +0100 Subject: [PATCH] Use built-in Self type in __init__.pyi when available Starting in python 3.11 the typing module has a Self type that does the equivalent of the SelfT typevar. This integrate a bit better with type checkers. --- src/frozendict/__init__.pyi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/frozendict/__init__.pyi b/src/frozendict/__init__.pyi index 0f0217e..42246db 100644 --- a/src/frozendict/__init__.pyi +++ b/src/frozendict/__init__.pyi @@ -1,5 +1,7 @@ from __future__ import annotations +import sys + from typing import ( TypeVar, overload, @@ -19,11 +21,15 @@ except ImportError: Tuple = tuple Type = type +if sys.version_info >= (3, 11): + from typing import Self as SelfT +else: + SelfT = TypeVar("SelfT", bound=frozendict[K, V]) + K = TypeVar("K") V = TypeVar("V", covariant=True) K2 = TypeVar("K2") V2 = TypeVar("V2", covariant=True) -SelfT = TypeVar("SelfT", bound=frozendict[K, V]) # noinspection PyPep8Naming class frozendict(Mapping[K, V]):