From: Daniele Varrazzo Date: Fri, 14 May 2021 14:51:17 +0000 (+0200) Subject: Make the dependency on typing_extension optional X-Git-Tag: 3.0.dev0~46 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e628ad55a58df170e02c80704b3fa225b5a20219;p=thirdparty%2Fpsycopg.git Make the dependency on typing_extension optional --- diff --git a/psycopg3/psycopg3/pq/proto.py b/psycopg3/psycopg3/pq/proto.py index 53c85c2ae..e8adca98f 100644 --- a/psycopg3/psycopg3/pq/proto.py +++ b/psycopg3/psycopg3/pq/proto.py @@ -6,9 +6,9 @@ Protocol objects to represent objects exposed by different pq implementations. from typing import Any, Callable, List, Optional, Sequence, Tuple, Union from typing import TYPE_CHECKING -from typing_extensions import Protocol from ._enums import Format +from ..utils.compat import Protocol if TYPE_CHECKING: from .misc import PGnotify, ConninfoOption, PGresAttDesc diff --git a/psycopg3/psycopg3/proto.py b/psycopg3/psycopg3/proto.py index 4bf1e7633..f6643e54d 100644 --- a/psycopg3/psycopg3/proto.py +++ b/psycopg3/psycopg3/proto.py @@ -7,10 +7,10 @@ Protocol objects representing different implementations of the same classes. from typing import Any, Callable, Generator, Mapping from typing import List, Optional, Sequence, Tuple, TypeVar, Union from typing import TYPE_CHECKING -from typing_extensions import Protocol from . import pq from ._enums import Format +from .utils.compat import Protocol if TYPE_CHECKING: from .sql import Composable diff --git a/psycopg3/psycopg3/rows.py b/psycopg3/psycopg3/rows.py index 4aafe3500..4fdab440c 100644 --- a/psycopg3/psycopg3/rows.py +++ b/psycopg3/psycopg3/rows.py @@ -9,9 +9,9 @@ import re from collections import namedtuple from typing import Any, Callable, Dict, NamedTuple, Sequence, Tuple, Type from typing import TypeVar, TYPE_CHECKING -from typing_extensions import Protocol from . import errors as e +from .utils.compat import Protocol if TYPE_CHECKING: from .cursor import AnyCursor diff --git a/psycopg3/psycopg3/utils/compat.py b/psycopg3/psycopg3/utils/compat.py index 0bbe62e32..7f97bc05a 100644 --- a/psycopg3/psycopg3/utils/compat.py +++ b/psycopg3/psycopg3/utils/compat.py @@ -8,6 +8,11 @@ import sys import asyncio from typing import Any, Awaitable, Generator, Optional, Union, TypeVar +if sys.version_info >= (3, 8): + from typing import Protocol +else: + from typing_extensions import Protocol + T = TypeVar("T") FutureT = Union["asyncio.Future[T]", Generator[Any, None, T], Awaitable[T]] @@ -44,4 +49,10 @@ else: Task = asyncio.Future -__all__ = ["asynccontextmanager", "get_running_loop", "create_task"] + +__all__ = [ + "Protocol", + "asynccontextmanager", + "create_task", + "get_running_loop", +] diff --git a/psycopg3/setup.cfg b/psycopg3/setup.cfg index b3d9de030..85164391f 100644 --- a/psycopg3/setup.cfg +++ b/psycopg3/setup.cfg @@ -30,8 +30,7 @@ python_requires = >= 3.6 packages = find: zip_safe = False install_requires = - typing_extensions - + typing_extensions; python_version < "3.8" [options.package_data] psycopg3_c = py.typed