Skip to content

Commit 83c56f0

Browse files
mikeprosserniMike Prosser
andauthored
nipanel: Extract typing backports into a submodule (#14)
* _typing.py * only use _typing.py for types that don't exist in typing * better ParamSpec --------- Co-authored-by: Mike Prosser <Mike.Prosser@emerson.com>
1 parent 173ee7f commit 83c56f0

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/nipanel/_panel_client.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,18 @@
44

55
import logging
66
import threading
7-
from typing import TYPE_CHECKING, Callable, TypeVar
7+
from typing import TypeVar, Callable
88

99
import grpc
1010
from ni.pythonpanel.v1.python_panel_service_pb2 import OpenPanelRequest
1111
from ni.pythonpanel.v1.python_panel_service_pb2_grpc import PythonPanelServiceStub
1212
from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient
1313
from ni_measurement_plugin_sdk_service.grpc.channelpool import GrpcChannelPool
1414

15-
_T = TypeVar("_T")
16-
17-
if TYPE_CHECKING:
18-
from typing_extensions import ParamSpec
19-
20-
_P = ParamSpec("_P")
15+
from nipanel._typing import ParamSpec
2116

17+
_P = ParamSpec("_P")
18+
_T = TypeVar("_T")
2219

2320
_logger = logging.getLogger(__name__)
2421

src/nipanel/_typing.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Single source for typing backports to avoid depending on typing_extensions at run time."""
2+
3+
from __future__ import annotations
4+
5+
import sys
6+
from typing import TYPE_CHECKING
7+
8+
if sys.version_info >= (3, 11):
9+
from typing import Self
10+
elif TYPE_CHECKING:
11+
from typing_extensions import Self
12+
else:
13+
Self = None
14+
15+
if sys.version_info >= (3, 10):
16+
from typing import ParamSpec
17+
elif TYPE_CHECKING:
18+
from typing_extensions import ParamSpec
19+
else:
20+
from typing import TypeVar as ParamSpec
21+
22+
__all__ = [
23+
"Self",
24+
"ParamSpec",
25+
]

0 commit comments

Comments
 (0)