diff --git a/src/nipanel/_panel_client.py b/src/nipanel/_panel_client.py index 9e62763..bfcdecb 100644 --- a/src/nipanel/_panel_client.py +++ b/src/nipanel/_panel_client.py @@ -4,7 +4,7 @@ import logging import threading -from typing import TYPE_CHECKING, Callable, TypeVar +from typing import TypeVar, Callable import grpc from ni.pythonpanel.v1.python_panel_service_pb2 import OpenPanelRequest @@ -12,13 +12,10 @@ from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient from ni_measurement_plugin_sdk_service.grpc.channelpool import GrpcChannelPool -_T = TypeVar("_T") - -if TYPE_CHECKING: - from typing_extensions import ParamSpec - - _P = ParamSpec("_P") +from nipanel._typing import ParamSpec +_P = ParamSpec("_P") +_T = TypeVar("_T") _logger = logging.getLogger(__name__) diff --git a/src/nipanel/_typing.py b/src/nipanel/_typing.py new file mode 100644 index 0000000..59817c5 --- /dev/null +++ b/src/nipanel/_typing.py @@ -0,0 +1,25 @@ +"""Single source for typing backports to avoid depending on typing_extensions at run time.""" + +from __future__ import annotations + +import sys +from typing import TYPE_CHECKING + +if sys.version_info >= (3, 11): + from typing import Self +elif TYPE_CHECKING: + from typing_extensions import Self +else: + Self = None + +if sys.version_info >= (3, 10): + from typing import ParamSpec +elif TYPE_CHECKING: + from typing_extensions import ParamSpec +else: + from typing import TypeVar as ParamSpec + +__all__ = [ + "Self", + "ParamSpec", +]