mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
avoid hard dependency on typing_extensions
This commit is contained in:
parent
cc51dace35
commit
3a4298d16c
|
@ -25,6 +25,19 @@ Internal Modules
|
|||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
:mod:`~PIL._typing` Module
|
||||
--------------------------
|
||||
|
||||
.. module:: PIL._typing
|
||||
|
||||
Provides a convenient way to import type hints that are not available
|
||||
on some supported Python versions.
|
||||
|
||||
.. py:data:: TypeGuard
|
||||
:value: typing.TypeGuard
|
||||
|
||||
See :py:obj:`typing.TypeGuard`.
|
||||
|
||||
:mod:`~PIL._util` Module
|
||||
------------------------
|
||||
|
||||
|
|
|
@ -37,9 +37,6 @@ classifiers = [
|
|||
dynamic = [
|
||||
"version",
|
||||
]
|
||||
dependencies = [
|
||||
'typing-extensions; python_version < "3.10"',
|
||||
]
|
||||
[project.optional-dependencies]
|
||||
docs = [
|
||||
"furo",
|
||||
|
@ -68,6 +65,9 @@ tests = [
|
|||
"pytest-cov",
|
||||
"pytest-timeout",
|
||||
]
|
||||
typing = [
|
||||
'typing-extensions; python_version < "3.10"',
|
||||
]
|
||||
xmp = [
|
||||
"defusedxml",
|
||||
]
|
||||
|
|
16
src/PIL/_typing.py
Normal file
16
src/PIL/_typing.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
import sys
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
from typing import TypeGuard
|
||||
else:
|
||||
try:
|
||||
from typing_extensions import TypeGuard
|
||||
except ImportError:
|
||||
from typing import Any, Type
|
||||
|
||||
class TypeGuard: # type: ignore[no-redef]
|
||||
def __class_getitem__(cls, item: Any) -> Type[bool]:
|
||||
return bool
|
||||
|
||||
|
||||
__all__ = ["TypeGuard"]
|
|
@ -1,14 +1,9 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any, NoReturn
|
||||
|
||||
if sys.version_info >= (3, 10):
|
||||
from typing import TypeGuard
|
||||
else:
|
||||
from typing_extensions import TypeGuard
|
||||
from ._typing import TypeGuard
|
||||
|
||||
|
||||
def is_path(f: Any) -> TypeGuard[bytes | str | Path]:
|
||||
|
|
Loading…
Reference in New Issue
Block a user