diff --git a/examples/analog_out/cont_gen_voltage_wfm_int_clk.py b/examples/analog_out/cont_gen_voltage_wfm_int_clk.py index 61555ef6f..ef61be259 100644 --- a/examples/analog_out/cont_gen_voltage_wfm_int_clk.py +++ b/examples/analog_out/cont_gen_voltage_wfm_int_clk.py @@ -4,8 +4,6 @@ waveform using an internal sample clock. """ -from typing import Tuple - import numpy as np import numpy.typing @@ -19,7 +17,7 @@ def generate_sine_wave( sampling_rate: float, number_of_samples: int, phase_in: float = 0.0, -) -> Tuple[numpy.typing.NDArray[numpy.double], float]: +) -> tuple[numpy.typing.NDArray[numpy.double], float]: """Generates a sine wave with a specified phase. Args: diff --git a/examples/analog_out/cont_gen_voltage_wfm_int_clk_every_n_samples_event.py b/examples/analog_out/cont_gen_voltage_wfm_int_clk_every_n_samples_event.py index 01d66fc78..27355aa75 100644 --- a/examples/analog_out/cont_gen_voltage_wfm_int_clk_every_n_samples_event.py +++ b/examples/analog_out/cont_gen_voltage_wfm_int_clk_every_n_samples_event.py @@ -6,8 +6,6 @@ the specified number of samples generation is complete. """ -from typing import Tuple - import numpy as np import numpy.typing @@ -21,7 +19,7 @@ def generate_sine_wave( sampling_rate: float, number_of_samples: int, phase_in: float = 0.0, -) -> Tuple[numpy.typing.NDArray[numpy.double], float]: +) -> tuple[numpy.typing.NDArray[numpy.double], float]: """Generates a sine wave with a specified phase. Args: diff --git a/examples/analog_out/cont_gen_voltage_wfm_int_clk_non_regen.py b/examples/analog_out/cont_gen_voltage_wfm_int_clk_non_regen.py index 9c0be568a..5d6451453 100644 --- a/examples/analog_out/cont_gen_voltage_wfm_int_clk_non_regen.py +++ b/examples/analog_out/cont_gen_voltage_wfm_int_clk_non_regen.py @@ -12,8 +12,6 @@ of your sample clock. """ -from typing import Tuple - import numpy as np import numpy.typing @@ -27,7 +25,7 @@ def generate_sine_wave( sampling_rate: float, number_of_samples: int, phase_in: float = 0.0, -) -> Tuple[numpy.typing.NDArray[numpy.double], float]: +) -> tuple[numpy.typing.NDArray[numpy.double], float]: """Generates a sine wave with a specified phase. Args: diff --git a/examples/nidaqmx_warnings.py b/examples/nidaqmx_warnings.py index 23ef56cf8..de7e33eb2 100644 --- a/examples/nidaqmx_warnings.py +++ b/examples/nidaqmx_warnings.py @@ -29,7 +29,7 @@ assert issubclass(w[-1].category, nidaqmx.DaqWarning) if w: - print("DaqWarning caught: {}\n".format(w[-1].message)) + print(f"DaqWarning caught: {w[-1].message}\n") # Raising warnings as exceptions. @@ -43,7 +43,7 @@ task.write([1.1, 2.2, 3.3, 4.4, 5.5], auto_start=True) task.stop() except nidaqmx.DaqWarning as e: - print("DaqWarning caught as exception: {}\n".format(e)) + print(f"DaqWarning caught as exception: {e}\n") assert e.error_code == DAQmxWarnings.STOPPED_BEFORE_DONE diff --git a/examples/synchronization/multi_function/ai_ao_sync.py b/examples/synchronization/multi_function/ai_ao_sync.py index 7c935b090..bd6e362a4 100644 --- a/examples/synchronization/multi_function/ai_ao_sync.py +++ b/examples/synchronization/multi_function/ai_ao_sync.py @@ -4,8 +4,6 @@ generate data at the same time, synchronized with one another. """ -from typing import Tuple - import numpy as np import numpy.typing @@ -39,7 +37,7 @@ def generate_sine_wave( sampling_rate: float, number_of_samples: int, phase_in: float = 0.0, -) -> Tuple[numpy.typing.NDArray[numpy.double], float]: +) -> tuple[numpy.typing.NDArray[numpy.double], float]: """Generates a sine wave with a specified phase. Args: diff --git a/generated/nidaqmx/_base_interpreter.py b/generated/nidaqmx/_base_interpreter.py index bd6f14541..46ee79a81 100644 --- a/generated/nidaqmx/_base_interpreter.py +++ b/generated/nidaqmx/_base_interpreter.py @@ -4,7 +4,9 @@ import abc import numpy from nitypes.waveform import AnalogWaveform, DigitalWaveform -from typing import Any, Sequence +from typing import Any + +from collections.abc import Sequence from nidaqmx.constants import WaveformAttributeMode diff --git a/generated/nidaqmx/_dotenvpath.py b/generated/nidaqmx/_dotenvpath.py index 19cad5a2d..de8789098 100644 --- a/generated/nidaqmx/_dotenvpath.py +++ b/generated/nidaqmx/_dotenvpath.py @@ -45,27 +45,12 @@ def _get_caller_path() -> Path | None: for frame, _ in traceback.walk_stack(inspect.currentframe()): if frame.f_code.co_filename: module_path = Path(frame.f_code.co_filename) - if _exists(module_path) and not module_path.is_relative_to(package_path): + if module_path.exists() and not module_path.is_relative_to(package_path): return module_path return None -# Path.exists() throws OSError when the path has invalid file characters. -# https://github.com/python/cpython/issues/79487 -if sys.version_info >= (3, 10): - - def _exists(path: Path) -> bool: - return path.exists() - -else: - - def _exists(path: Path) -> bool: - import os - - return os.path.exists(path) - - def _get_package_path() -> Path: """Get the path of this package.""" module = sys.modules[__package__] diff --git a/generated/nidaqmx/_feature_toggles.py b/generated/nidaqmx/_feature_toggles.py index 9484031a6..fa19c442e 100644 --- a/generated/nidaqmx/_feature_toggles.py +++ b/generated/nidaqmx/_feature_toggles.py @@ -4,8 +4,9 @@ import functools import sys +from collections.abc import Callable from enum import Enum -from typing import TYPE_CHECKING, Callable, TypeVar +from typing import TYPE_CHECKING, TypeVar from decouple import AutoConfig, Undefined, undefined @@ -13,10 +14,7 @@ from nidaqmx.errors import FeatureNotSupportedError if TYPE_CHECKING: - if sys.version_info >= (3, 10): - from typing import ParamSpec - else: - from typing_extensions import ParamSpec + from typing import ParamSpec if sys.version_info >= (3, 11): from typing import Self diff --git a/generated/nidaqmx/_grpc_interpreter.py b/generated/nidaqmx/_grpc_interpreter.py index d772b9919..165378c26 100644 --- a/generated/nidaqmx/_grpc_interpreter.py +++ b/generated/nidaqmx/_grpc_interpreter.py @@ -6,10 +6,11 @@ import typing import warnings from nitypes.waveform import AnalogWaveform, DigitalWaveform -from typing import Any, Callable, Generic, Sequence, TypeVar +from typing import Any, Generic, TypeVar + +from collections.abc import Callable, Sequence import google.protobuf.message -from google.protobuf.timestamp_pb2 import Timestamp as GrpcTimestamp import grpc import numpy diff --git a/generated/nidaqmx/_install_daqmx.py b/generated/nidaqmx/_install_daqmx.py index 97ca0bc76..4a30e42c2 100644 --- a/generated/nidaqmx/_install_daqmx.py +++ b/generated/nidaqmx/_install_daqmx.py @@ -10,7 +10,7 @@ import sys import tempfile import zipfile -from typing import Generator +from collections.abc import Generator from urllib.parse import urlparse import click diff --git a/generated/nidaqmx/_lib.py b/generated/nidaqmx/_lib.py index 8fccba52b..c751e5318 100644 --- a/generated/nidaqmx/_lib.py +++ b/generated/nidaqmx/_lib.py @@ -17,7 +17,7 @@ ) if TYPE_CHECKING: - from typing_extensions import TypeAlias + from typing import TypeAlias _DAQ_NOT_FOUND_MESSAGE = ( diff --git a/generated/nidaqmx/_library_interpreter.py b/generated/nidaqmx/_library_interpreter.py index 7f4f98cff..343bb9ff8 100644 --- a/generated/nidaqmx/_library_interpreter.py +++ b/generated/nidaqmx/_library_interpreter.py @@ -6,12 +6,13 @@ import numpy import platform import warnings -import sys from enum import Enum from datetime import timezone from hightime import datetime as ht_datetime from hightime import timedelta as ht_timedelta -from typing import Any, Callable, List, Sequence, Tuple, TYPE_CHECKING, Union +from typing import Any, TYPE_CHECKING + +from collections.abc import Callable, Sequence from nidaqmx._base_interpreter import BaseEventHandler, BaseInterpreter from nidaqmx._lib import lib_importer, ctypes_byte_str, c_bool32, wrapped_ndpointer, TaskHandle @@ -23,10 +24,7 @@ from nitypes.waveform import AnalogWaveform, DigitalWaveform, SampleIntervalMode, Timing, ExtendedPropertyDictionary if TYPE_CHECKING: - if sys.version_info >= (3, 10): - from typing import TypeAlias - else: - from typing_extensions import TypeAlias + from typing import TypeAlias _logger = logging.getLogger(__name__) _was_runtime_environment_set = None @@ -2777,7 +2775,7 @@ def get_digital_power_up_states(self, device_name, channel_name): state = [] args = [device_name] - argtypes: List[type] = [ctypes_byte_str] + argtypes: list[type] = [ctypes_byte_str] for index in range(len(channel_name)): state_element = ctypes.c_int32() @@ -2803,7 +2801,7 @@ def get_digital_pull_up_pull_down_states(self, device_name, channel_name): state = [] args = [device_name] - argtypes: List[type] = [ctypes_byte_str] + argtypes: list[type] = [ctypes_byte_str] for index in range(len(channel_name)): state_element = ctypes.c_int32() @@ -5011,7 +5009,7 @@ def self_test_device(self, device_name): def set_analog_power_up_states( self, device_name, channel_names, state, channel_type): args = [device_name] - argtypes: List[type] = [ctypes_byte_str] + argtypes: list[type] = [ctypes_byte_str] for index in range(len(channel_names)): @@ -5204,7 +5202,7 @@ def set_digital_logic_family_power_up_state( def set_digital_power_up_states(self, device_name, channel_names, state): args = [device_name] - argtypes: List[type] = [ctypes_byte_str] + argtypes: list[type] = [ctypes_byte_str] for index in range(len(channel_names)): @@ -5226,7 +5224,7 @@ def set_digital_power_up_states(self, device_name, channel_names, state): def set_digital_pull_up_pull_down_states( self, device_name, channel_names, state): args = [device_name] - argtypes: List[type] = [ctypes_byte_str] + argtypes: list[type] = [ctypes_byte_str] for index in range(len(channel_names)): @@ -6481,7 +6479,7 @@ def _internal_read_analog_waveform_ex( properties: Sequence[ExtendedPropertyDictionary] | None, t0_array: numpy.typing.NDArray[numpy.int64] | None, dt_array: numpy.typing.NDArray[numpy.int64] | None, - ) -> Tuple[ + ) -> tuple[ int, # error code int, # The number of samples per channel that were read ]: @@ -6535,7 +6533,7 @@ def _internal_read_analog_waveform_per_chan( properties: Sequence[ExtendedPropertyDictionary] | None, t0_array: numpy.typing.NDArray[numpy.int64] | None, dt_array: numpy.typing.NDArray[numpy.int64] | None, - ) -> Tuple[ + ) -> tuple[ int, # error code int, # The number of samples per channel that were read ]: @@ -6651,7 +6649,7 @@ def _invoke_callback( def _set_waveform_timings( self, - waveforms: Sequence[Union[AnalogWaveform[numpy.float64], DigitalWaveform[numpy.uint8]]], + waveforms: Sequence[AnalogWaveform[numpy.float64] | DigitalWaveform[numpy.uint8]], t0_array: numpy.typing.NDArray[numpy.int64], dt_array: numpy.typing.NDArray[numpy.int64] ) -> None: @@ -6835,7 +6833,7 @@ def _internal_read_digital_waveform( t0_array: numpy.typing.NDArray[numpy.int64] | None, dt_array: numpy.typing.NDArray[numpy.int64] | None, bytes_per_chan_array: numpy.typing.NDArray[numpy.uint32] | None = None, - ) -> Tuple[ + ) -> tuple[ int, # error code int, # The number of samples per channel that were read ]: @@ -7049,7 +7047,7 @@ def _internal_write_analog_waveform_per_chan( auto_start: bool, timeout: float, write_arrays: Sequence[numpy.typing.NDArray[numpy.float64]], - ) -> Tuple[ + ) -> tuple[ int, # error code int, # The number of samples per channel that were written ]: @@ -7176,7 +7174,7 @@ def _internal_write_digital_waveform( data_layout: int, write_array: numpy.typing.NDArray[numpy.uint8], bytes_per_chan_array: numpy.typing.NDArray[numpy.uint32] | None = None, - ) -> Tuple[ + ) -> tuple[ int, # error code int, # The number of samples per channel that were written ]: diff --git a/generated/nidaqmx/_linux_installation_commands.py b/generated/nidaqmx/_linux_installation_commands.py index cacd90176..91e688ebe 100644 --- a/generated/nidaqmx/_linux_installation_commands.py +++ b/generated/nidaqmx/_linux_installation_commands.py @@ -1,7 +1,7 @@ from __future__ import annotations +from collections.abc import Callable from dataclasses import dataclass -from typing import Callable def _get_version_ubuntu(dist_version: str) -> str: diff --git a/generated/nidaqmx/stream_writers/_digital_multi_channel_writer.py b/generated/nidaqmx/stream_writers/_digital_multi_channel_writer.py index b2024aaf0..9b1f391f7 100644 --- a/generated/nidaqmx/stream_writers/_digital_multi_channel_writer.py +++ b/generated/nidaqmx/stream_writers/_digital_multi_channel_writer.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import Any, Sequence +from collections.abc import Sequence +from typing import Any from nitypes.waveform import DigitalWaveform diff --git a/generated/nidaqmx/system/_collections/device_collection.py b/generated/nidaqmx/system/_collections/device_collection.py index e1f13a38f..40a34bdd0 100644 --- a/generated/nidaqmx/system/_collections/device_collection.py +++ b/generated/nidaqmx/system/_collections/device_collection.py @@ -67,7 +67,7 @@ def __getitem__(self, index): return [_DeviceAlternateConstructor(name, self._interpreter) for name in device_names] else: raise DaqError( - 'Invalid index type "{}" used to access collection.'.format(type(index)), + f'Invalid index type "{type(index)}" used to access collection.', DAQmxErrors.UNKNOWN, ) diff --git a/generated/nidaqmx/system/_collections/persisted_channel_collection.py b/generated/nidaqmx/system/_collections/persisted_channel_collection.py index 06c0910e3..f705ed0dd 100644 --- a/generated/nidaqmx/system/_collections/persisted_channel_collection.py +++ b/generated/nidaqmx/system/_collections/persisted_channel_collection.py @@ -74,7 +74,7 @@ def __getitem__(self, index): ] else: raise DaqError( - 'Invalid index type "{}" used to access collection.'.format(type(index)), + f'Invalid index type "{type(index)}" used to access collection.', DAQmxErrors.UNKNOWN, ) diff --git a/generated/nidaqmx/system/_collections/persisted_scale_collection.py b/generated/nidaqmx/system/_collections/persisted_scale_collection.py index dc1785c06..cae71a0f4 100644 --- a/generated/nidaqmx/system/_collections/persisted_scale_collection.py +++ b/generated/nidaqmx/system/_collections/persisted_scale_collection.py @@ -70,7 +70,7 @@ def __getitem__(self, index): return [_PersistedScaleAlternateConstructor(name, self._interpreter) for name in names] else: raise DaqError( - 'Invalid index type "{}" used to access collection.'.format(type(index)), + f'Invalid index type "{type(index)}" used to access collection.', DAQmxErrors.UNKNOWN, ) diff --git a/generated/nidaqmx/system/_collections/persisted_task_collection.py b/generated/nidaqmx/system/_collections/persisted_task_collection.py index 43b1a01e2..d381be2ec 100644 --- a/generated/nidaqmx/system/_collections/persisted_task_collection.py +++ b/generated/nidaqmx/system/_collections/persisted_task_collection.py @@ -70,7 +70,7 @@ def __getitem__(self, index): return [_PersistedTaskAlternateConstructor(name, self._interpreter) for name in names] else: raise DaqError( - 'Invalid index type "{}" used to access collection.'.format(type(index)), + f'Invalid index type "{type(index)}" used to access collection.', DAQmxErrors.UNKNOWN, ) diff --git a/generated/nidaqmx/system/_collections/physical_channel_collection.py b/generated/nidaqmx/system/_collections/physical_channel_collection.py index 5248e15c9..79cb46b67 100644 --- a/generated/nidaqmx/system/_collections/physical_channel_collection.py +++ b/generated/nidaqmx/system/_collections/physical_channel_collection.py @@ -87,7 +87,7 @@ def __getitem__(self, index): ] else: raise DaqError( - 'Invalid index type "{}" used to access collection.'.format(type(index)), + f'Invalid index type "{type(index)}" used to access collection.', DAQmxErrors.UNKNOWN, ) diff --git a/generated/nidaqmx/system/_watchdog_modules/expiration_states_collection.py b/generated/nidaqmx/system/_watchdog_modules/expiration_states_collection.py index 6fee56327..441507996 100644 --- a/generated/nidaqmx/system/_watchdog_modules/expiration_states_collection.py +++ b/generated/nidaqmx/system/_watchdog_modules/expiration_states_collection.py @@ -41,5 +41,5 @@ def __getitem__(self, index): return ExpirationState(self._handle, index, self._interpreter) else: raise DaqError( - 'Invalid index type "{}" used to access expiration states.'.format(type(index)), -1 + f'Invalid index type "{type(index)}" used to access expiration states.', -1 ) diff --git a/generated/nidaqmx/system/physical_channel.py b/generated/nidaqmx/system/physical_channel.py index 5502d9294..38740f73e 100644 --- a/generated/nidaqmx/system/physical_channel.py +++ b/generated/nidaqmx/system/physical_channel.py @@ -659,8 +659,7 @@ def clear_teds(self): self._interpreter.clear_teds( self._name) - def configure_teds( - self, file_path: Optional[Union[str, pathlib.PurePath]]=None): + def configure_teds(self, file_path: str | pathlib.PurePath | None=None): """ Associates TEDS information with the physical channel you specify. If you do not specify the filename of a data sheet in @@ -708,7 +707,7 @@ def write_to_teds_from_array( self._name, bit_stream, basic_teds_options.value) def write_to_teds_from_file( - self, file_path: Optional[Union[str, pathlib.PurePath]]=None, + self, file_path: str | pathlib.PurePath | None=None, basic_teds_options=WriteBasicTEDSOptions.DO_NOT_WRITE): """ Writes data from a virtual TEDS file to the TEDS sensor. diff --git a/generated/nidaqmx/task/_in_stream.py b/generated/nidaqmx/task/_in_stream.py index 699adcfdb..14a848fa0 100644 --- a/generated/nidaqmx/task/_in_stream.py +++ b/generated/nidaqmx/task/_in_stream.py @@ -333,7 +333,7 @@ def input_onbrd_buf_size(self): return val @property - def logging_file_path(self) -> Optional[pathlib.Path]: + def logging_file_path(self) -> pathlib.Path | None: """ pathlib.Path: Specifies the path to the TDMS file to which you want to log data. If the file path is changed while the @@ -349,7 +349,7 @@ def logging_file_path(self) -> Optional[pathlib.Path]: return pathlib.Path(val) if val else None @logging_file_path.setter - def logging_file_path(self, val: Optional[Union[str, pathlib.PurePath]]): + def logging_file_path(self, val: str | pathlib.PurePath | None): if val is None: val = "" val = str(val) @@ -997,7 +997,7 @@ def _calculate_num_samps_per_chan(self, num_samps_per_chan): return num_samps_per_chan def configure_logging( - self, file_path: Union[str, pathlib.PurePath], logging_mode=LoggingMode.LOG_AND_READ, + self, file_path: str | pathlib.PurePath, logging_mode=LoggingMode.LOG_AND_READ, group_name="", operation=LoggingOperation.OPEN_OR_CREATE): """ Configures TDMS file logging for the task. @@ -1090,7 +1090,7 @@ def read(self, number_of_samples_per_channel=READ_ALL_AVAILABLE): if samp_size_in_bits == 32: if has_negative_range: - dtype: Type[numpy.generic] = numpy.int32 + dtype: type[numpy.generic] = numpy.int32 else: dtype = numpy.uint32 elif samp_size_in_bits == 16: @@ -1238,7 +1238,7 @@ def read_into(self, numpy_array): return samples_read - def start_new_file(self, file_path: Union[str, pathlib.PurePath]): + def start_new_file(self, file_path: str | pathlib.PurePath): """ Starts a new TDMS file the next time data is written to disk. diff --git a/generated/nidaqmx/task/_task.py b/generated/nidaqmx/task/_task.py index 0c0269af6..95b14bd9e 100644 --- a/generated/nidaqmx/task/_task.py +++ b/generated/nidaqmx/task/_task.py @@ -2,9 +2,9 @@ import threading import warnings -from collections.abc import Iterable +from collections.abc import Iterable, Sequence from enum import Enum -from typing import Any, NoReturn, Sequence +from typing import Any, NoReturn import numpy from nitypes.waveform import AnalogWaveform, DigitalWaveform diff --git a/generated/nidaqmx/task/collections/_channel_collection.py b/generated/nidaqmx/task/collections/_channel_collection.py index a42200f53..452238883 100644 --- a/generated/nidaqmx/task/collections/_channel_collection.py +++ b/generated/nidaqmx/task/collections/_channel_collection.py @@ -63,7 +63,7 @@ def __getitem__(self, index): channel_names = index else: raise DaqError( - 'Invalid index type "{}" used to access channels.'.format(type(index)), + f'Invalid index type "{type(index)}" used to access channels.', DAQmxErrors.UNKNOWN, ) diff --git a/src/codegen/stub_generator.py b/src/codegen/stub_generator.py index 6d6e47a59..5a0316a06 100644 --- a/src/codegen/stub_generator.py +++ b/src/codegen/stub_generator.py @@ -2,7 +2,7 @@ import os import pathlib -from typing import Sequence +from collections.abc import Sequence import grpc_tools.protoc import pkg_resources diff --git a/src/codegen/templates/_base_interpreter.py.mako b/src/codegen/templates/_base_interpreter.py.mako index c59e9dab7..76f65813b 100644 --- a/src/codegen/templates/_base_interpreter.py.mako +++ b/src/codegen/templates/_base_interpreter.py.mako @@ -15,7 +15,9 @@ from __future__ import annotations import abc import numpy from nitypes.waveform import AnalogWaveform, DigitalWaveform -from typing import Any, Sequence +from typing import Any + +from collections.abc import Sequence from nidaqmx.constants import WaveformAttributeMode diff --git a/src/codegen/templates/_grpc_interpreter.py.mako b/src/codegen/templates/_grpc_interpreter.py.mako index 36a1467c5..1ca5fae19 100644 --- a/src/codegen/templates/_grpc_interpreter.py.mako +++ b/src/codegen/templates/_grpc_interpreter.py.mako @@ -23,10 +23,11 @@ import threading import typing import warnings from nitypes.waveform import AnalogWaveform, DigitalWaveform -from typing import Any, Callable, Generic, Sequence, TypeVar +from typing import Any, Generic, TypeVar + +from collections.abc import Callable, Sequence import google.protobuf.message -from google.protobuf.timestamp_pb2 import Timestamp as GrpcTimestamp import grpc import numpy diff --git a/src/codegen/templates/_library_interpreter.py.mako b/src/codegen/templates/_library_interpreter.py.mako index 3f26814d0..02d3bdd54 100644 --- a/src/codegen/templates/_library_interpreter.py.mako +++ b/src/codegen/templates/_library_interpreter.py.mako @@ -23,12 +23,13 @@ import logging import numpy import platform import warnings -import sys from enum import Enum from datetime import timezone from hightime import datetime as ht_datetime from hightime import timedelta as ht_timedelta -from typing import Any, Callable, List, Sequence, Tuple, TYPE_CHECKING, Union +from typing import Any, TYPE_CHECKING + +from collections.abc import Callable, Sequence from nidaqmx._base_interpreter import BaseEventHandler, BaseInterpreter from nidaqmx._lib import lib_importer, ctypes_byte_str, c_bool32, wrapped_ndpointer, TaskHandle @@ -40,10 +41,7 @@ from nitypes.waveform.typing import ExtendedPropertyValue from nitypes.waveform import AnalogWaveform, DigitalWaveform, SampleIntervalMode, Timing, ExtendedPropertyDictionary if TYPE_CHECKING: - if sys.version_info >= (3, 10): - from typing import TypeAlias - else: - from typing_extensions import TypeAlias + from typing import TypeAlias _logger = logging.getLogger(__name__) _was_runtime_environment_set = None @@ -286,7 +284,7 @@ class LibraryInterpreter(BaseInterpreter): properties: Sequence[ExtendedPropertyDictionary] | None, t0_array: numpy.typing.NDArray[numpy.int64] | None, dt_array: numpy.typing.NDArray[numpy.int64] | None, - ) -> Tuple[ + ) -> tuple[ int, # error code int, # The number of samples per channel that were read ]: @@ -340,7 +338,7 @@ class LibraryInterpreter(BaseInterpreter): properties: Sequence[ExtendedPropertyDictionary] | None, t0_array: numpy.typing.NDArray[numpy.int64] | None, dt_array: numpy.typing.NDArray[numpy.int64] | None, - ) -> Tuple[ + ) -> tuple[ int, # error code int, # The number of samples per channel that were read ]: @@ -456,7 +454,7 @@ class LibraryInterpreter(BaseInterpreter): def _set_waveform_timings( self, - waveforms: Sequence[Union[AnalogWaveform[numpy.float64], DigitalWaveform[numpy.uint8]]], + waveforms: Sequence[AnalogWaveform[numpy.float64] | DigitalWaveform[numpy.uint8]], t0_array: numpy.typing.NDArray[numpy.int64], dt_array: numpy.typing.NDArray[numpy.int64] ) -> None: @@ -641,7 +639,7 @@ class LibraryInterpreter(BaseInterpreter): t0_array: numpy.typing.NDArray[numpy.int64] | None, dt_array: numpy.typing.NDArray[numpy.int64] | None, bytes_per_chan_array: numpy.typing.NDArray[numpy.uint32] | None = None, - ) -> Tuple[ + ) -> tuple[ int, # error code int, # The number of samples per channel that were read ]: @@ -862,7 +860,7 @@ class LibraryInterpreter(BaseInterpreter): auto_start: bool, timeout: float, write_arrays: Sequence[numpy.typing.NDArray[numpy.float64]], - ) -> Tuple[ + ) -> tuple[ int, # error code int, # The number of samples per channel that were written ]: @@ -989,7 +987,7 @@ class LibraryInterpreter(BaseInterpreter): data_layout: int, write_array: numpy.typing.NDArray[numpy.uint8], bytes_per_chan_array: numpy.typing.NDArray[numpy.uint32] | None = None, - ) -> Tuple[ + ) -> tuple[ int, # error code int, # The number of samples per channel that were written ]: diff --git a/src/codegen/templates/library_interpreter/exec_cdecl_c_function_call.py.mako b/src/codegen/templates/library_interpreter/exec_cdecl_c_function_call.py.mako index 0f1cc02f8..3285ded60 100644 --- a/src/codegen/templates/library_interpreter/exec_cdecl_c_function_call.py.mako +++ b/src/codegen/templates/library_interpreter/exec_cdecl_c_function_call.py.mako @@ -17,7 +17,7 @@ argument_definition_lines = get_argument_definition_lines_for_varargs(varargs_parameters) %>\ args = [device_name] - argtypes: List[type] = [ctypes_byte_str] + argtypes: list[type] = [ctypes_byte_str] for index in range(${varargs_array_length}): %for instantiation_line in instantiation_lines: diff --git a/src/codegen/templates/property_getter_template.py.mako b/src/codegen/templates/property_getter_template.py.mako index 823c361a7..6a9363206 100644 --- a/src/codegen/templates/property_getter_template.py.mako +++ b/src/codegen/templates/property_getter_template.py.mako @@ -5,7 +5,7 @@ %>\ %if attribute.name in ATTRIBUTE_WITH_FILE_PATH_TYPE: @property - def ${attribute.name}(self) -> Optional[pathlib.Path]: + def ${attribute.name}(self) -> pathlib.Path | None: """ ${"pathlib.Path: " + attribute.python_description | docstring_wrap(initial_indent=8, subsequent_indent=12)} """ diff --git a/src/codegen/templates/property_setter_template.py.mako b/src/codegen/templates/property_setter_template.py.mako index 77eb8144b..bb286dbf7 100644 --- a/src/codegen/templates/property_setter_template.py.mako +++ b/src/codegen/templates/property_setter_template.py.mako @@ -4,7 +4,7 @@ %>\ @${attribute.name}.setter %if attribute.name in ATTRIBUTE_WITH_FILE_PATH_TYPE: - def ${attribute.name}(self, val: Optional[Union[str, pathlib.PurePath]]): + def ${attribute.name}(self, val: str | pathlib.PurePath | None): %else: def ${attribute.name}(self, val): %endif diff --git a/src/codegen/templates/task/_in_stream.py.mako b/src/codegen/templates/task/_in_stream.py.mako index 0d3b13c05..0c0078ddc 100644 --- a/src/codegen/templates/task/_in_stream.py.mako +++ b/src/codegen/templates/task/_in_stream.py.mako @@ -98,7 +98,7 @@ ${property_template.script_property(attribute)}\ return num_samps_per_chan def configure_logging( - self, file_path: Union[str, pathlib.PurePath], logging_mode=LoggingMode.LOG_AND_READ, + self, file_path: str | pathlib.PurePath, logging_mode=LoggingMode.LOG_AND_READ, group_name="", operation=LoggingOperation.OPEN_OR_CREATE): """ Configures TDMS file logging for the task. @@ -191,7 +191,7 @@ ${property_template.script_property(attribute)}\ if samp_size_in_bits == 32: if has_negative_range: - dtype: Type[numpy.generic] = numpy.int32 + dtype: type[numpy.generic] = numpy.int32 else: dtype = numpy.uint32 elif samp_size_in_bits == 16: @@ -339,7 +339,7 @@ ${property_template.script_property(attribute)}\ return samples_read - def start_new_file(self, file_path: Union[str, pathlib.PurePath]): + def start_new_file(self, file_path: str | pathlib.PurePath): """ Starts a new TDMS file the next time data is written to disk. diff --git a/src/codegen/utilities/function_helpers.py b/src/codegen/utilities/function_helpers.py index a640bf3f3..4ba242474 100644 --- a/src/codegen/utilities/function_helpers.py +++ b/src/codegen/utilities/function_helpers.py @@ -108,7 +108,7 @@ def get_parameter_signature(is_python_factory, sorted_params): param_type = "" param_default = param.default if is_path_type(param): - param_type = ": Optional[Union[str, pathlib.PurePath]]" + param_type = ": str | pathlib.PurePath | None" param_default = "None" if param._optional: params_with_defaults.append(f"{param.parameter_name}{param_type}={param_default}") diff --git a/src/handwritten/_dotenvpath.py b/src/handwritten/_dotenvpath.py index 19cad5a2d..de8789098 100644 --- a/src/handwritten/_dotenvpath.py +++ b/src/handwritten/_dotenvpath.py @@ -45,27 +45,12 @@ def _get_caller_path() -> Path | None: for frame, _ in traceback.walk_stack(inspect.currentframe()): if frame.f_code.co_filename: module_path = Path(frame.f_code.co_filename) - if _exists(module_path) and not module_path.is_relative_to(package_path): + if module_path.exists() and not module_path.is_relative_to(package_path): return module_path return None -# Path.exists() throws OSError when the path has invalid file characters. -# https://github.com/python/cpython/issues/79487 -if sys.version_info >= (3, 10): - - def _exists(path: Path) -> bool: - return path.exists() - -else: - - def _exists(path: Path) -> bool: - import os - - return os.path.exists(path) - - def _get_package_path() -> Path: """Get the path of this package.""" module = sys.modules[__package__] diff --git a/src/handwritten/_feature_toggles.py b/src/handwritten/_feature_toggles.py index 9484031a6..fa19c442e 100644 --- a/src/handwritten/_feature_toggles.py +++ b/src/handwritten/_feature_toggles.py @@ -4,8 +4,9 @@ import functools import sys +from collections.abc import Callable from enum import Enum -from typing import TYPE_CHECKING, Callable, TypeVar +from typing import TYPE_CHECKING, TypeVar from decouple import AutoConfig, Undefined, undefined @@ -13,10 +14,7 @@ from nidaqmx.errors import FeatureNotSupportedError if TYPE_CHECKING: - if sys.version_info >= (3, 10): - from typing import ParamSpec - else: - from typing_extensions import ParamSpec + from typing import ParamSpec if sys.version_info >= (3, 11): from typing import Self diff --git a/src/handwritten/_install_daqmx.py b/src/handwritten/_install_daqmx.py index 97ca0bc76..4a30e42c2 100644 --- a/src/handwritten/_install_daqmx.py +++ b/src/handwritten/_install_daqmx.py @@ -10,7 +10,7 @@ import sys import tempfile import zipfile -from typing import Generator +from collections.abc import Generator from urllib.parse import urlparse import click diff --git a/src/handwritten/_lib.py b/src/handwritten/_lib.py index 8fccba52b..c751e5318 100644 --- a/src/handwritten/_lib.py +++ b/src/handwritten/_lib.py @@ -17,7 +17,7 @@ ) if TYPE_CHECKING: - from typing_extensions import TypeAlias + from typing import TypeAlias _DAQ_NOT_FOUND_MESSAGE = ( diff --git a/src/handwritten/_linux_installation_commands.py b/src/handwritten/_linux_installation_commands.py index cacd90176..91e688ebe 100644 --- a/src/handwritten/_linux_installation_commands.py +++ b/src/handwritten/_linux_installation_commands.py @@ -1,7 +1,7 @@ from __future__ import annotations +from collections.abc import Callable from dataclasses import dataclass -from typing import Callable def _get_version_ubuntu(dist_version: str) -> str: diff --git a/src/handwritten/stream_writers/_digital_multi_channel_writer.py b/src/handwritten/stream_writers/_digital_multi_channel_writer.py index b2024aaf0..9b1f391f7 100644 --- a/src/handwritten/stream_writers/_digital_multi_channel_writer.py +++ b/src/handwritten/stream_writers/_digital_multi_channel_writer.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import Any, Sequence +from collections.abc import Sequence +from typing import Any from nitypes.waveform import DigitalWaveform diff --git a/src/handwritten/system/_collections/device_collection.py b/src/handwritten/system/_collections/device_collection.py index e1f13a38f..40a34bdd0 100644 --- a/src/handwritten/system/_collections/device_collection.py +++ b/src/handwritten/system/_collections/device_collection.py @@ -67,7 +67,7 @@ def __getitem__(self, index): return [_DeviceAlternateConstructor(name, self._interpreter) for name in device_names] else: raise DaqError( - 'Invalid index type "{}" used to access collection.'.format(type(index)), + f'Invalid index type "{type(index)}" used to access collection.', DAQmxErrors.UNKNOWN, ) diff --git a/src/handwritten/system/_collections/persisted_channel_collection.py b/src/handwritten/system/_collections/persisted_channel_collection.py index 06c0910e3..f705ed0dd 100644 --- a/src/handwritten/system/_collections/persisted_channel_collection.py +++ b/src/handwritten/system/_collections/persisted_channel_collection.py @@ -74,7 +74,7 @@ def __getitem__(self, index): ] else: raise DaqError( - 'Invalid index type "{}" used to access collection.'.format(type(index)), + f'Invalid index type "{type(index)}" used to access collection.', DAQmxErrors.UNKNOWN, ) diff --git a/src/handwritten/system/_collections/persisted_scale_collection.py b/src/handwritten/system/_collections/persisted_scale_collection.py index dc1785c06..cae71a0f4 100644 --- a/src/handwritten/system/_collections/persisted_scale_collection.py +++ b/src/handwritten/system/_collections/persisted_scale_collection.py @@ -70,7 +70,7 @@ def __getitem__(self, index): return [_PersistedScaleAlternateConstructor(name, self._interpreter) for name in names] else: raise DaqError( - 'Invalid index type "{}" used to access collection.'.format(type(index)), + f'Invalid index type "{type(index)}" used to access collection.', DAQmxErrors.UNKNOWN, ) diff --git a/src/handwritten/system/_collections/persisted_task_collection.py b/src/handwritten/system/_collections/persisted_task_collection.py index 43b1a01e2..d381be2ec 100644 --- a/src/handwritten/system/_collections/persisted_task_collection.py +++ b/src/handwritten/system/_collections/persisted_task_collection.py @@ -70,7 +70,7 @@ def __getitem__(self, index): return [_PersistedTaskAlternateConstructor(name, self._interpreter) for name in names] else: raise DaqError( - 'Invalid index type "{}" used to access collection.'.format(type(index)), + f'Invalid index type "{type(index)}" used to access collection.', DAQmxErrors.UNKNOWN, ) diff --git a/src/handwritten/system/_collections/physical_channel_collection.py b/src/handwritten/system/_collections/physical_channel_collection.py index 5248e15c9..79cb46b67 100644 --- a/src/handwritten/system/_collections/physical_channel_collection.py +++ b/src/handwritten/system/_collections/physical_channel_collection.py @@ -87,7 +87,7 @@ def __getitem__(self, index): ] else: raise DaqError( - 'Invalid index type "{}" used to access collection.'.format(type(index)), + f'Invalid index type "{type(index)}" used to access collection.', DAQmxErrors.UNKNOWN, ) diff --git a/src/handwritten/system/_watchdog_modules/expiration_states_collection.py b/src/handwritten/system/_watchdog_modules/expiration_states_collection.py index 6fee56327..441507996 100644 --- a/src/handwritten/system/_watchdog_modules/expiration_states_collection.py +++ b/src/handwritten/system/_watchdog_modules/expiration_states_collection.py @@ -41,5 +41,5 @@ def __getitem__(self, index): return ExpirationState(self._handle, index, self._interpreter) else: raise DaqError( - 'Invalid index type "{}" used to access expiration states.'.format(type(index)), -1 + f'Invalid index type "{type(index)}" used to access expiration states.', -1 ) diff --git a/src/handwritten/task/_task.py b/src/handwritten/task/_task.py index 0c0269af6..95b14bd9e 100644 --- a/src/handwritten/task/_task.py +++ b/src/handwritten/task/_task.py @@ -2,9 +2,9 @@ import threading import warnings -from collections.abc import Iterable +from collections.abc import Iterable, Sequence from enum import Enum -from typing import Any, NoReturn, Sequence +from typing import Any, NoReturn import numpy from nitypes.waveform import AnalogWaveform, DigitalWaveform diff --git a/src/handwritten/task/collections/_channel_collection.py b/src/handwritten/task/collections/_channel_collection.py index a42200f53..452238883 100644 --- a/src/handwritten/task/collections/_channel_collection.py +++ b/src/handwritten/task/collections/_channel_collection.py @@ -63,7 +63,7 @@ def __getitem__(self, index): channel_names = index else: raise DaqError( - 'Invalid index type "{}" used to access channels.'.format(type(index)), + f'Invalid index type "{type(index)}" used to access channels.', DAQmxErrors.UNKNOWN, ) diff --git a/tests/_event_utils.py b/tests/_event_utils.py index 6f9d1c7bd..069938659 100644 --- a/tests/_event_utils.py +++ b/tests/_event_utils.py @@ -2,7 +2,8 @@ import threading import time -from typing import Callable, Generic, NamedTuple, TypeVar, Union +from collections.abc import Callable +from typing import Generic, NamedTuple, TypeVar, Union class DoneEvent(NamedTuple): diff --git a/tests/acceptance/test_multi_threading.py b/tests/acceptance/test_multi_threading.py index 17be16d2c..16ea36585 100644 --- a/tests/acceptance/test_multi_threading.py +++ b/tests/acceptance/test_multi_threading.py @@ -5,10 +5,11 @@ import random import threading import time +from collections.abc import Callable, Sequence from concurrent.futures import Future, ThreadPoolExecutor from contextlib import ExitStack from threading import Barrier, Semaphore -from typing import Any, Callable, Sequence +from typing import Any import pytest diff --git a/tests/component/_digital_utils.py b/tests/component/_digital_utils.py index 03235607b..80be6526f 100644 --- a/tests/component/_digital_utils.py +++ b/tests/component/_digital_utils.py @@ -2,7 +2,8 @@ from __future__ import annotations -from typing import Any, Callable, TypeVar +from collections.abc import Callable +from typing import Any, TypeVar import numpy from nitypes.waveform import DigitalWaveform diff --git a/tests/component/conftest.py b/tests/component/conftest.py index 413c681c8..9cfd5225c 100644 --- a/tests/component/conftest.py +++ b/tests/component/conftest.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import Callable +from collections.abc import Callable import pytest diff --git a/tests/component/stream_readers/test_analog_multi_channel_reader.py b/tests/component/stream_readers/test_analog_multi_channel_reader.py index 44e435c80..bfaac86ef 100644 --- a/tests/component/stream_readers/test_analog_multi_channel_reader.py +++ b/tests/component/stream_readers/test_analog_multi_channel_reader.py @@ -2,7 +2,7 @@ import ctypes import math -from typing import Callable +from collections.abc import Callable import numpy import pytest diff --git a/tests/component/stream_readers/test_analog_single_channel_reader.py b/tests/component/stream_readers/test_analog_single_channel_reader.py index bff71f629..ce0f032a6 100644 --- a/tests/component/stream_readers/test_analog_single_channel_reader.py +++ b/tests/component/stream_readers/test_analog_single_channel_reader.py @@ -2,7 +2,7 @@ import ctypes import math -from typing import Callable +from collections.abc import Callable import numpy import pytest diff --git a/tests/component/stream_readers/test_digital_multi_channel_reader.py b/tests/component/stream_readers/test_digital_multi_channel_reader.py index a7dd14232..5398a79e7 100644 --- a/tests/component/stream_readers/test_digital_multi_channel_reader.py +++ b/tests/component/stream_readers/test_digital_multi_channel_reader.py @@ -2,7 +2,7 @@ import ctypes import math -from typing import Callable +from collections.abc import Callable import numpy import pytest diff --git a/tests/component/stream_readers/test_digital_single_channel_reader.py b/tests/component/stream_readers/test_digital_single_channel_reader.py index b57e151cb..2b68d455a 100644 --- a/tests/component/stream_readers/test_digital_single_channel_reader.py +++ b/tests/component/stream_readers/test_digital_single_channel_reader.py @@ -2,7 +2,7 @@ import ctypes import math -from typing import Callable +from collections.abc import Callable import numpy import pytest diff --git a/tests/component/stream_writers/test_digital_multi_channel_writer.py b/tests/component/stream_writers/test_digital_multi_channel_writer.py index 8b43ea941..c2a76e277 100644 --- a/tests/component/stream_writers/test_digital_multi_channel_writer.py +++ b/tests/component/stream_writers/test_digital_multi_channel_writer.py @@ -2,7 +2,7 @@ import ctypes import math -from typing import Callable +from collections.abc import Callable import numpy import pytest diff --git a/tests/component/test_stream_writers_co.py b/tests/component/test_stream_writers_co.py index f6fb3dd9a..6eb43c954 100644 --- a/tests/component/test_stream_writers_co.py +++ b/tests/component/test_stream_writers_co.py @@ -2,7 +2,7 @@ import ctypes import math -from typing import Callable +from collections.abc import Callable import numpy import pytest diff --git a/tests/component/test_watchdog.py b/tests/component/test_watchdog.py index 06415c871..993db866e 100644 --- a/tests/component/test_watchdog.py +++ b/tests/component/test_watchdog.py @@ -1,7 +1,7 @@ from __future__ import annotations import weakref -from typing import Callable +from collections.abc import Callable import pytest diff --git a/tests/conftest.py b/tests/conftest.py index bcf79509d..a74956ac9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,9 +4,10 @@ import contextlib import pathlib +from collections.abc import Callable, Generator from concurrent.futures import ThreadPoolExecutor from enum import Enum -from typing import TYPE_CHECKING, Callable, Generator +from typing import TYPE_CHECKING import pytest diff --git a/tests/helpers.py b/tests/helpers.py index a2d0fd368..a772e9b6a 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -4,7 +4,7 @@ import contextlib import pathlib -from typing import Generator +from collections.abc import Generator from nidaqmx.system.physical_channel import PhysicalChannel diff --git a/tests/unit/_task_utils.py b/tests/unit/_task_utils.py index 08b4fbd3f..82d1b346c 100644 --- a/tests/unit/_task_utils.py +++ b/tests/unit/_task_utils.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import Iterable +from collections.abc import Iterable from unittest.mock import Mock from pytest_mock import MockerFixture diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 8a3ef36ef..57ac1af6f 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import Generator +from collections.abc import Generator from unittest.mock import Mock import pytest