mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46: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:
|
:undoc-members:
|
||||||
:show-inheritance:
|
: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
|
:mod:`~PIL._util` Module
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,6 @@ classifiers = [
|
||||||
dynamic = [
|
dynamic = [
|
||||||
"version",
|
"version",
|
||||||
]
|
]
|
||||||
dependencies = [
|
|
||||||
'typing-extensions; python_version < "3.10"',
|
|
||||||
]
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
docs = [
|
docs = [
|
||||||
"furo",
|
"furo",
|
||||||
|
@ -68,6 +65,9 @@ tests = [
|
||||||
"pytest-cov",
|
"pytest-cov",
|
||||||
"pytest-timeout",
|
"pytest-timeout",
|
||||||
]
|
]
|
||||||
|
typing = [
|
||||||
|
'typing-extensions; python_version < "3.10"',
|
||||||
|
]
|
||||||
xmp = [
|
xmp = [
|
||||||
"defusedxml",
|
"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
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, NoReturn
|
from typing import Any, NoReturn
|
||||||
|
from ._typing import TypeGuard
|
||||||
if sys.version_info >= (3, 10):
|
|
||||||
from typing import TypeGuard
|
|
||||||
else:
|
|
||||||
from typing_extensions import TypeGuard
|
|
||||||
|
|
||||||
|
|
||||||
def is_path(f: Any) -> TypeGuard[bytes | str | Path]:
|
def is_path(f: Any) -> TypeGuard[bytes | str | Path]:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user