From a3867f4ff0b8a3bd07661826d8d3e3a97ac072df Mon Sep 17 00:00:00 2001 From: deathaxe Date: Tue, 23 Apr 2024 15:50:45 +0200 Subject: [PATCH] Make more use of typing_extensions module (#2460) * Make more use of typing_extensions module This commit replaces various homegrown type definitions by imports from typing_extensions module. * Simplify typing_extensions imports The `typing_extensions` module is a compatibility layer between python versions. Required types can always be imported from it, even if available via `typing` natively. --- plugin/core/typing.py | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/plugin/core/typing.py b/plugin/core/typing.py index baa293b99..600d71202 100644 --- a/plugin/core/typing.py +++ b/plugin/core/typing.py @@ -27,18 +27,16 @@ cast, final, ) +from typing_extensions import ( # noqa: F401 + NotRequired, + ParamSpec, + Required, + TypeGuard, +) if sys.version_info >= (3, 11): from enum import StrEnum # noqa: F401 - from typing import ( # noqa: F401 - NotRequired, - ParamSpec, - Required, - TypeGuard, - ) else: - _T = TypeVar("_T") - class StrEnum(str, Enum): """ Naive polyfill for Python 3.11's StrEnum. @@ -48,19 +46,3 @@ class StrEnum(str, Enum): __format__ = str.__format__ __str__ = str.__str__ - - class NotRequired(Type, Generic[_T]): # type: ignore - pass - - class ParamSpec(Type): # type: ignore - args = ... - kwargs = ... - - def __init__(*args, **kwargs) -> None: # type: ignore - pass - - class Required(Type, Generic[_T]): # type: ignore - pass - - class TypeGuard(Type, Generic[_T]): # type: ignore - pass