Skip to content

Commit 4771be1

Browse files
authored
examples: Enable mypy for the example programs (#879)
* examples: Enable mypy * examples: Fix error: Incompatible types in assignment (expression has type "list[bool]", variable has type "bool") [assignment] * examples: Ignore missing imports for nptdms * github: Update check.yml to install examples dependency group * docs: Add --with examples to CONTRIBUTING.md * examples: Fix Linux mypy errors
1 parent f8b6958 commit 4771be1

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ jobs:
2525
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
2626
with:
2727
path: .venv
28-
key: nidaqmx-all-extras-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}
28+
key: nidaqmx-all-extras-and-examples-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock') }}
2929
- name: Install dependencies
3030
run: |
3131
python -m pip install --upgrade pip
32-
poetry install --all-extras
32+
poetry install --all-extras --with examples
3333
- name: Run linters
3434
run: poetry run ni-python-styleguide lint
3535
- name: Run mypy (Linux)

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ To contribute to this project, it is recommended that you follow these steps:
1919
1. Ensure you have [poetry](https://python-poetry.org/) [installed](https://python-poetry.org/docs/#installation)
2020
2. Clone the repository using `git clone https://github.com/ni/nidaqmx-python.git`
2121
3. Get the submodules using `git submodule update --init --recursive`
22-
3. Install **nidaqmx** dependencies using `poetry install --all-extras`
22+
3. Install **nidaqmx** dependencies using `poetry install --all-extras --with examples`
2323
4. Run the regression tests on your system (see Testing section). At this point, if any tests fail, do not
2424
begin development. Try to investigate these failures. If you're unable to do so, report an issue
2525
through our [GitHub issues page](http://github.com/ni/nidaqmx-python/issues).

examples/digital_out/gen_dig_line_int_clk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from nidaqmx.constants import AcquisitionType, LineGrouping
99

1010
with nidaqmx.Task() as task:
11-
data: bool = [bool(i % 2) for i in range(1000)]
11+
data = [bool(i % 2) for i in range(1000)]
1212

1313
task.do_channels.add_do_chan("Dev1/port0/line0", line_grouping=LineGrouping.CHAN_PER_LINE)
1414
task.timing.cfg_samp_clk_timing(

examples/playrec.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import numpy as np
44

5-
import nidaqmx as ni
5+
import nidaqmx
6+
import nidaqmx.system
67
from nidaqmx.constants import WAIT_INFINITELY
78

89

910
def query_devices():
1011
"""Queries all the device information connected to the local system."""
11-
local = ni.system.System.local()
12+
local = nidaqmx.system.System.local()
1213
for device in local.devices:
1314
print(f"Device Name: {device.name}, Product Type: {device.product_type}")
1415
print("Input channels:", [chan.name for chan in device.ai_physical_chans])
@@ -35,11 +36,11 @@ def playrec(data, samplerate, input_mapping, output_mapping):
3536
Recorded data
3637
3738
"""
38-
devices = ni.system.System.local().devices
39+
devices = nidaqmx.system.System.local().devices
3940
data = np.asarray(data).T
4041
nsamples = data.shape[1]
4142

42-
with ni.Task() as read_task, ni.Task() as write_task:
43+
with nidaqmx.Task() as read_task, nidaqmx.Task() as write_task:
4344
for i, o in enumerate(output_mapping):
4445
aochan = write_task.ao_channels.add_ao_voltage_chan(
4546
o,

examples/system_properties.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Examples for using system properties in DAQmx."""
22

3-
import nidaqmx
3+
import nidaqmx.system
44

55
local_system = nidaqmx.system.System.local()
66
driver_version = local_system.driver_version

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ requires = ["poetry-core>=2.1,<3.0"]
158158
build-backend = "poetry.core.masonry.api"
159159

160160
[tool.mypy]
161-
files = "generated/,tests/"
161+
files = "examples/,generated/,tests/"
162162
check_untyped_defs = true
163163
namespace_packages = true
164164
warn_redundant_casts = true
@@ -178,6 +178,8 @@ module = [
178178
"nidaqmx.*",
179179
# https://github.com/ionelmc/pytest-benchmark/issues/212 - Add type annotations
180180
"pytest_benchmark.*",
181+
# https://github.com/adamreeve/npTDMS/issues/301 - Type Hints/Annotations
182+
"nptdms.*",
181183
]
182184
ignore_missing_imports = true
183185

0 commit comments

Comments
 (0)