Skip to content

Commit 7ea2b61

Browse files
committed
codegen: Upgrade generated to Python 3.10 syntax
1 parent 8099553 commit 7ea2b61

13 files changed

+51
-50
lines changed

generated/nidaqmx/_base_interpreter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import abc
55
import numpy
66
from nitypes.waveform import AnalogWaveform, DigitalWaveform
7-
from typing import Any, Sequence
7+
from typing import Any
8+
9+
from collections.abc import Sequence
810
from nidaqmx.constants import WaveformAttributeMode
911

1012

generated/nidaqmx/_grpc_interpreter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import typing
77
import warnings
88
from nitypes.waveform import AnalogWaveform, DigitalWaveform
9-
from typing import Any, Callable, Generic, Sequence, TypeVar
9+
from typing import Any, Generic, TypeVar
10+
11+
from collections.abc import Callable, Sequence
1012

1113
import google.protobuf.message
12-
from google.protobuf.timestamp_pb2 import Timestamp as GrpcTimestamp
1314
import grpc
1415
import numpy
1516

generated/nidaqmx/_library_interpreter.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
import numpy
77
import platform
88
import warnings
9-
import sys
109
from enum import Enum
1110
from datetime import timezone
1211
from hightime import datetime as ht_datetime
1312
from hightime import timedelta as ht_timedelta
14-
from typing import Any, Callable, List, Sequence, Tuple, TYPE_CHECKING, Union
13+
from typing import Any, TYPE_CHECKING
14+
15+
from collections.abc import Callable, Sequence
1516

1617
from nidaqmx._base_interpreter import BaseEventHandler, BaseInterpreter
1718
from nidaqmx._lib import lib_importer, ctypes_byte_str, c_bool32, wrapped_ndpointer, TaskHandle
@@ -23,10 +24,7 @@
2324
from nitypes.waveform import AnalogWaveform, DigitalWaveform, SampleIntervalMode, Timing, ExtendedPropertyDictionary
2425

2526
if TYPE_CHECKING:
26-
if sys.version_info >= (3, 10):
27-
from typing import TypeAlias
28-
else:
29-
from typing_extensions import TypeAlias
27+
from typing import TypeAlias
3028

3129
_logger = logging.getLogger(__name__)
3230
_was_runtime_environment_set = None
@@ -2777,7 +2775,7 @@ def get_digital_power_up_states(self, device_name, channel_name):
27772775
state = []
27782776

27792777
args = [device_name]
2780-
argtypes: List[type] = [ctypes_byte_str]
2778+
argtypes: list[type] = [ctypes_byte_str]
27812779

27822780
for index in range(len(channel_name)):
27832781
state_element = ctypes.c_int32()
@@ -2803,7 +2801,7 @@ def get_digital_pull_up_pull_down_states(self, device_name, channel_name):
28032801
state = []
28042802

28052803
args = [device_name]
2806-
argtypes: List[type] = [ctypes_byte_str]
2804+
argtypes: list[type] = [ctypes_byte_str]
28072805

28082806
for index in range(len(channel_name)):
28092807
state_element = ctypes.c_int32()
@@ -5011,7 +5009,7 @@ def self_test_device(self, device_name):
50115009
def set_analog_power_up_states(
50125010
self, device_name, channel_names, state, channel_type):
50135011
args = [device_name]
5014-
argtypes: List[type] = [ctypes_byte_str]
5012+
argtypes: list[type] = [ctypes_byte_str]
50155013

50165014
for index in range(len(channel_names)):
50175015

@@ -5204,7 +5202,7 @@ def set_digital_logic_family_power_up_state(
52045202

52055203
def set_digital_power_up_states(self, device_name, channel_names, state):
52065204
args = [device_name]
5207-
argtypes: List[type] = [ctypes_byte_str]
5205+
argtypes: list[type] = [ctypes_byte_str]
52085206

52095207
for index in range(len(channel_names)):
52105208

@@ -5226,7 +5224,7 @@ def set_digital_power_up_states(self, device_name, channel_names, state):
52265224
def set_digital_pull_up_pull_down_states(
52275225
self, device_name, channel_names, state):
52285226
args = [device_name]
5229-
argtypes: List[type] = [ctypes_byte_str]
5227+
argtypes: list[type] = [ctypes_byte_str]
52305228

52315229
for index in range(len(channel_names)):
52325230

@@ -6481,7 +6479,7 @@ def _internal_read_analog_waveform_ex(
64816479
properties: Sequence[ExtendedPropertyDictionary] | None,
64826480
t0_array: numpy.typing.NDArray[numpy.int64] | None,
64836481
dt_array: numpy.typing.NDArray[numpy.int64] | None,
6484-
) -> Tuple[
6482+
) -> tuple[
64856483
int, # error code
64866484
int, # The number of samples per channel that were read
64876485
]:
@@ -6535,7 +6533,7 @@ def _internal_read_analog_waveform_per_chan(
65356533
properties: Sequence[ExtendedPropertyDictionary] | None,
65366534
t0_array: numpy.typing.NDArray[numpy.int64] | None,
65376535
dt_array: numpy.typing.NDArray[numpy.int64] | None,
6538-
) -> Tuple[
6536+
) -> tuple[
65396537
int, # error code
65406538
int, # The number of samples per channel that were read
65416539
]:
@@ -6651,7 +6649,7 @@ def _invoke_callback(
66516649

66526650
def _set_waveform_timings(
66536651
self,
6654-
waveforms: Sequence[Union[AnalogWaveform[numpy.float64], DigitalWaveform[numpy.uint8]]],
6652+
waveforms: Sequence[AnalogWaveform[numpy.float64] | DigitalWaveform[numpy.uint8]],
66556653
t0_array: numpy.typing.NDArray[numpy.int64],
66566654
dt_array: numpy.typing.NDArray[numpy.int64]
66576655
) -> None:
@@ -6835,7 +6833,7 @@ def _internal_read_digital_waveform(
68356833
t0_array: numpy.typing.NDArray[numpy.int64] | None,
68366834
dt_array: numpy.typing.NDArray[numpy.int64] | None,
68376835
bytes_per_chan_array: numpy.typing.NDArray[numpy.uint32] | None = None,
6838-
) -> Tuple[
6836+
) -> tuple[
68396837
int, # error code
68406838
int, # The number of samples per channel that were read
68416839
]:
@@ -7049,7 +7047,7 @@ def _internal_write_analog_waveform_per_chan(
70497047
auto_start: bool,
70507048
timeout: float,
70517049
write_arrays: Sequence[numpy.typing.NDArray[numpy.float64]],
7052-
) -> Tuple[
7050+
) -> tuple[
70537051
int, # error code
70547052
int, # The number of samples per channel that were written
70557053
]:
@@ -7176,7 +7174,7 @@ def _internal_write_digital_waveform(
71767174
data_layout: int,
71777175
write_array: numpy.typing.NDArray[numpy.uint8],
71787176
bytes_per_chan_array: numpy.typing.NDArray[numpy.uint32] | None = None,
7179-
) -> Tuple[
7177+
) -> tuple[
71807178
int, # error code
71817179
int, # The number of samples per channel that were written
71827180
]:

generated/nidaqmx/system/physical_channel.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,7 @@ def clear_teds(self):
659659
self._interpreter.clear_teds(
660660
self._name)
661661

662-
def configure_teds(
663-
self, file_path: Optional[Union[str, pathlib.PurePath]]=None):
662+
def configure_teds(self, file_path: str | pathlib.PurePath | None=None):
664663
"""
665664
Associates TEDS information with the physical channel you
666665
specify. If you do not specify the filename of a data sheet in
@@ -708,7 +707,7 @@ def write_to_teds_from_array(
708707
self._name, bit_stream, basic_teds_options.value)
709708

710709
def write_to_teds_from_file(
711-
self, file_path: Optional[Union[str, pathlib.PurePath]]=None,
710+
self, file_path: str | pathlib.PurePath | None=None,
712711
basic_teds_options=WriteBasicTEDSOptions.DO_NOT_WRITE):
713712
"""
714713
Writes data from a virtual TEDS file to the TEDS sensor.

generated/nidaqmx/task/_in_stream.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def input_onbrd_buf_size(self):
333333
return val
334334

335335
@property
336-
def logging_file_path(self) -> Optional[pathlib.Path]:
336+
def logging_file_path(self) -> pathlib.Path | None:
337337
"""
338338
pathlib.Path: Specifies the path to the TDMS file to which you
339339
want to log data. If the file path is changed while the
@@ -349,7 +349,7 @@ def logging_file_path(self) -> Optional[pathlib.Path]:
349349
return pathlib.Path(val) if val else None
350350

351351
@logging_file_path.setter
352-
def logging_file_path(self, val: Optional[Union[str, pathlib.PurePath]]):
352+
def logging_file_path(self, val: str | pathlib.PurePath | None):
353353
if val is None:
354354
val = ""
355355
val = str(val)
@@ -997,7 +997,7 @@ def _calculate_num_samps_per_chan(self, num_samps_per_chan):
997997
return num_samps_per_chan
998998

999999
def configure_logging(
1000-
self, file_path: Union[str, pathlib.PurePath], logging_mode=LoggingMode.LOG_AND_READ,
1000+
self, file_path: str | pathlib.PurePath, logging_mode=LoggingMode.LOG_AND_READ,
10011001
group_name="", operation=LoggingOperation.OPEN_OR_CREATE):
10021002
"""
10031003
Configures TDMS file logging for the task.
@@ -1090,7 +1090,7 @@ def read(self, number_of_samples_per_channel=READ_ALL_AVAILABLE):
10901090

10911091
if samp_size_in_bits == 32:
10921092
if has_negative_range:
1093-
dtype: Type[numpy.generic] = numpy.int32
1093+
dtype: type[numpy.generic] = numpy.int32
10941094
else:
10951095
dtype = numpy.uint32
10961096
elif samp_size_in_bits == 16:
@@ -1238,7 +1238,7 @@ def read_into(self, numpy_array):
12381238

12391239
return samples_read
12401240

1241-
def start_new_file(self, file_path: Union[str, pathlib.PurePath]):
1241+
def start_new_file(self, file_path: str | pathlib.PurePath):
12421242
"""
12431243
Starts a new TDMS file the next time data is written to disk.
12441244

src/codegen/templates/_base_interpreter.py.mako

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ from __future__ import annotations
1515
import abc
1616
import numpy
1717
from nitypes.waveform import AnalogWaveform, DigitalWaveform
18-
from typing import Any, Sequence
18+
from typing import Any
19+
20+
from collections.abc import Sequence
1921
from nidaqmx.constants import WaveformAttributeMode
2022

2123

src/codegen/templates/_grpc_interpreter.py.mako

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ import threading
2323
import typing
2424
import warnings
2525
from nitypes.waveform import AnalogWaveform, DigitalWaveform
26-
from typing import Any, Callable, Generic, Sequence, TypeVar
26+
from typing import Any, Generic, TypeVar
27+
28+
from collections.abc import Callable, Sequence
2729

2830
import google.protobuf.message
29-
from google.protobuf.timestamp_pb2 import Timestamp as GrpcTimestamp
3031
import grpc
3132
import numpy
3233

src/codegen/templates/_library_interpreter.py.mako

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ import logging
2323
import numpy
2424
import platform
2525
import warnings
26-
import sys
2726
from enum import Enum
2827
from datetime import timezone
2928
from hightime import datetime as ht_datetime
3029
from hightime import timedelta as ht_timedelta
31-
from typing import Any, Callable, List, Sequence, Tuple, TYPE_CHECKING, Union
30+
from typing import Any, TYPE_CHECKING
31+
32+
from collections.abc import Callable, Sequence
3233

3334
from nidaqmx._base_interpreter import BaseEventHandler, BaseInterpreter
3435
from nidaqmx._lib import lib_importer, ctypes_byte_str, c_bool32, wrapped_ndpointer, TaskHandle
@@ -40,10 +41,7 @@ from nitypes.waveform.typing import ExtendedPropertyValue
4041
from nitypes.waveform import AnalogWaveform, DigitalWaveform, SampleIntervalMode, Timing, ExtendedPropertyDictionary
4142

4243
if TYPE_CHECKING:
43-
if sys.version_info >= (3, 10):
44-
from typing import TypeAlias
45-
else:
46-
from typing_extensions import TypeAlias
44+
from typing import TypeAlias
4745

4846
_logger = logging.getLogger(__name__)
4947
_was_runtime_environment_set = None
@@ -286,7 +284,7 @@ class LibraryInterpreter(BaseInterpreter):
286284
properties: Sequence[ExtendedPropertyDictionary] | None,
287285
t0_array: numpy.typing.NDArray[numpy.int64] | None,
288286
dt_array: numpy.typing.NDArray[numpy.int64] | None,
289-
) -> Tuple[
287+
) -> tuple[
290288
int, # error code
291289
int, # The number of samples per channel that were read
292290
]:
@@ -340,7 +338,7 @@ class LibraryInterpreter(BaseInterpreter):
340338
properties: Sequence[ExtendedPropertyDictionary] | None,
341339
t0_array: numpy.typing.NDArray[numpy.int64] | None,
342340
dt_array: numpy.typing.NDArray[numpy.int64] | None,
343-
) -> Tuple[
341+
) -> tuple[
344342
int, # error code
345343
int, # The number of samples per channel that were read
346344
]:
@@ -456,7 +454,7 @@ class LibraryInterpreter(BaseInterpreter):
456454

457455
def _set_waveform_timings(
458456
self,
459-
waveforms: Sequence[Union[AnalogWaveform[numpy.float64], DigitalWaveform[numpy.uint8]]],
457+
waveforms: Sequence[AnalogWaveform[numpy.float64] | DigitalWaveform[numpy.uint8]],
460458
t0_array: numpy.typing.NDArray[numpy.int64],
461459
dt_array: numpy.typing.NDArray[numpy.int64]
462460
) -> None:
@@ -641,7 +639,7 @@ class LibraryInterpreter(BaseInterpreter):
641639
t0_array: numpy.typing.NDArray[numpy.int64] | None,
642640
dt_array: numpy.typing.NDArray[numpy.int64] | None,
643641
bytes_per_chan_array: numpy.typing.NDArray[numpy.uint32] | None = None,
644-
) -> Tuple[
642+
) -> tuple[
645643
int, # error code
646644
int, # The number of samples per channel that were read
647645
]:
@@ -862,7 +860,7 @@ class LibraryInterpreter(BaseInterpreter):
862860
auto_start: bool,
863861
timeout: float,
864862
write_arrays: Sequence[numpy.typing.NDArray[numpy.float64]],
865-
) -> Tuple[
863+
) -> tuple[
866864
int, # error code
867865
int, # The number of samples per channel that were written
868866
]:
@@ -989,7 +987,7 @@ class LibraryInterpreter(BaseInterpreter):
989987
data_layout: int,
990988
write_array: numpy.typing.NDArray[numpy.uint8],
991989
bytes_per_chan_array: numpy.typing.NDArray[numpy.uint32] | None = None,
992-
) -> Tuple[
990+
) -> tuple[
993991
int, # error code
994992
int, # The number of samples per channel that were written
995993
]:

src/codegen/templates/library_interpreter/exec_cdecl_c_function_call.py.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
argument_definition_lines = get_argument_definition_lines_for_varargs(varargs_parameters)
1818
%>\
1919
args = [device_name]
20-
argtypes: List[type] = [ctypes_byte_str]
20+
argtypes: list[type] = [ctypes_byte_str]
2121

2222
for index in range(${varargs_array_length}):
2323
%for instantiation_line in instantiation_lines:

src/codegen/templates/property_getter_template.py.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
%>\
66
%if attribute.name in ATTRIBUTE_WITH_FILE_PATH_TYPE:
77
@property
8-
def ${attribute.name}(self) -> Optional[pathlib.Path]:
8+
def ${attribute.name}(self) -> pathlib.Path | None:
99
"""
1010
${"pathlib.Path: " + attribute.python_description | docstring_wrap(initial_indent=8, subsequent_indent=12)}
1111
"""

0 commit comments

Comments
 (0)