Skip to content

Commit

Permalink
Make more use of typing_extensions module (#2460)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
deathaxe authored Apr 23, 2024
1 parent 4c8da78 commit a3867f4
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions plugin/core/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

0 comments on commit a3867f4

Please sign in to comment.