Skip to content

Commit cd16d28

Browse files
authored
nidaqmx: Upgrade to Python 3.10 syntax (#871)
* codegen: Upgrade to Python 3.10 syntax * handwritten: Upgrade to Python 3.10 syntax * tests: Upgrade to Python 3.10 syntax * examplaes: Upgrade to Python 3.10 syntax * generated: Regenerate handwritten * codegen: Upgrade generated to Python 3.10 syntax
1 parent 837a018 commit cd16d28

File tree

62 files changed

+113
-148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+113
-148
lines changed

examples/analog_out/cont_gen_voltage_wfm_int_clk.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
waveform using an internal sample clock.
55
"""
66

7-
from typing import Tuple
8-
97
import numpy as np
108
import numpy.typing
119

@@ -19,7 +17,7 @@ def generate_sine_wave(
1917
sampling_rate: float,
2018
number_of_samples: int,
2119
phase_in: float = 0.0,
22-
) -> Tuple[numpy.typing.NDArray[numpy.double], float]:
20+
) -> tuple[numpy.typing.NDArray[numpy.double], float]:
2321
"""Generates a sine wave with a specified phase.
2422
2523
Args:

examples/analog_out/cont_gen_voltage_wfm_int_clk_every_n_samples_event.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
the specified number of samples generation is complete.
77
"""
88

9-
from typing import Tuple
10-
119
import numpy as np
1210
import numpy.typing
1311

@@ -21,7 +19,7 @@ def generate_sine_wave(
2119
sampling_rate: float,
2220
number_of_samples: int,
2321
phase_in: float = 0.0,
24-
) -> Tuple[numpy.typing.NDArray[numpy.double], float]:
22+
) -> tuple[numpy.typing.NDArray[numpy.double], float]:
2523
"""Generates a sine wave with a specified phase.
2624
2725
Args:

examples/analog_out/cont_gen_voltage_wfm_int_clk_non_regen.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
of your sample clock.
1313
"""
1414

15-
from typing import Tuple
16-
1715
import numpy as np
1816
import numpy.typing
1917

@@ -27,7 +25,7 @@ def generate_sine_wave(
2725
sampling_rate: float,
2826
number_of_samples: int,
2927
phase_in: float = 0.0,
30-
) -> Tuple[numpy.typing.NDArray[numpy.double], float]:
28+
) -> tuple[numpy.typing.NDArray[numpy.double], float]:
3129
"""Generates a sine wave with a specified phase.
3230
3331
Args:

examples/nidaqmx_warnings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
assert issubclass(w[-1].category, nidaqmx.DaqWarning)
3030

3131
if w:
32-
print("DaqWarning caught: {}\n".format(w[-1].message))
32+
print(f"DaqWarning caught: {w[-1].message}\n")
3333

3434

3535
# Raising warnings as exceptions.
@@ -43,7 +43,7 @@
4343
task.write([1.1, 2.2, 3.3, 4.4, 5.5], auto_start=True)
4444
task.stop()
4545
except nidaqmx.DaqWarning as e:
46-
print("DaqWarning caught as exception: {}\n".format(e))
46+
print(f"DaqWarning caught as exception: {e}\n")
4747
assert e.error_code == DAQmxWarnings.STOPPED_BEFORE_DONE
4848

4949

examples/synchronization/multi_function/ai_ao_sync.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
generate data at the same time, synchronized with one another.
55
"""
66

7-
from typing import Tuple
8-
97
import numpy as np
108
import numpy.typing
119

@@ -39,7 +37,7 @@ def generate_sine_wave(
3937
sampling_rate: float,
4038
number_of_samples: int,
4139
phase_in: float = 0.0,
42-
) -> Tuple[numpy.typing.NDArray[numpy.double], float]:
40+
) -> tuple[numpy.typing.NDArray[numpy.double], float]:
4341
"""Generates a sine wave with a specified phase.
4442
4543
Args:

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/_dotenvpath.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,12 @@ def _get_caller_path() -> Path | None:
4545
for frame, _ in traceback.walk_stack(inspect.currentframe()):
4646
if frame.f_code.co_filename:
4747
module_path = Path(frame.f_code.co_filename)
48-
if _exists(module_path) and not module_path.is_relative_to(package_path):
48+
if module_path.exists() and not module_path.is_relative_to(package_path):
4949
return module_path
5050

5151
return None
5252

5353

54-
# Path.exists() throws OSError when the path has invalid file characters.
55-
# https://github.com/python/cpython/issues/79487
56-
if sys.version_info >= (3, 10):
57-
58-
def _exists(path: Path) -> bool:
59-
return path.exists()
60-
61-
else:
62-
63-
def _exists(path: Path) -> bool:
64-
import os
65-
66-
return os.path.exists(path)
67-
68-
6954
def _get_package_path() -> Path:
7055
"""Get the path of this package."""
7156
module = sys.modules[__package__]

generated/nidaqmx/_feature_toggles.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44

55
import functools
66
import sys
7+
from collections.abc import Callable
78
from enum import Enum
8-
from typing import TYPE_CHECKING, Callable, TypeVar
9+
from typing import TYPE_CHECKING, TypeVar
910

1011
from decouple import AutoConfig, Undefined, undefined
1112

1213
from nidaqmx._dotenvpath import get_dotenv_search_path
1314
from nidaqmx.errors import FeatureNotSupportedError
1415

1516
if TYPE_CHECKING:
16-
if sys.version_info >= (3, 10):
17-
from typing import ParamSpec
18-
else:
19-
from typing_extensions import ParamSpec
17+
from typing import ParamSpec
2018

2119
if sys.version_info >= (3, 11):
2220
from typing import Self

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/_install_daqmx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import sys
1111
import tempfile
1212
import zipfile
13-
from typing import Generator
13+
from collections.abc import Generator
1414
from urllib.parse import urlparse
1515

1616
import click

0 commit comments

Comments
 (0)