Skip to content

Commit 71d3a7f

Browse files
authored
mypy: Enable --warn-unused-ignores and remove unused ignores (#749)
* pyproject.toml: Configure mypy to warn about unused ignores, except for mypy-protobuf codegen * codegen: Remove type: ignore for ctypes callback with no arguments * tests: Remove type: ignore for property with different get/set types * tests: Remove type: ignore for ZoneInfo construction * tests: Work around missing type hints for watchdog expir states * tests: Remove type: ignore for property with different get/set types * tests: Fix import spacing
1 parent f10feb9 commit 71d3a7f

File tree

8 files changed

+26
-14
lines changed

8 files changed

+26
-14
lines changed

generated/nidaqmx/_library_interpreter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5843,7 +5843,7 @@ def unregister_done_event(self, task):
58435843
ctypes.POINTER(ctypes.c_void_p)]
58445844

58455845
options = 0
5846-
callback_method_ptr = DAQmxDoneEventCallbackPtr() # type: ignore # typeshed is missing no-argument constructor overload
5846+
callback_method_ptr = DAQmxDoneEventCallbackPtr()
58475847
callback_data = None
58485848

58495849
error_code = cfunc(
@@ -5867,7 +5867,7 @@ def unregister_every_n_samples_event(
58675867

58685868
n_samples = 0
58695869
options = 0
5870-
callback_method_ptr = DAQmxEveryNSamplesEventCallbackPtr() # type: ignore # typeshed is missing no-argument constructor overload
5870+
callback_method_ptr = DAQmxEveryNSamplesEventCallbackPtr()
58715871
callback_data = None
58725872

58735873
error_code = cfunc(
@@ -5890,7 +5890,7 @@ def unregister_signal_event(self, task, signal_id):
58905890
ctypes.POINTER(ctypes.c_void_p)]
58915891

58925892
options = 0
5893-
callback_method_ptr = DAQmxSignalEventCallbackPtr() # type: ignore # typeshed is missing no-argument constructor overload
5893+
callback_method_ptr = DAQmxSignalEventCallbackPtr()
58945894
callback_data = None
58955895

58965896
error_code = cfunc(

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ plugins = "numpy.typing.mypy_plugin"
141141
warn_redundant_casts = true
142142
warn_unreachable = true
143143
warn_unused_configs = true
144+
warn_unused_ignores = true
144145

145146
[[tool.mypy.overrides]]
146147
module = [
@@ -157,6 +158,11 @@ module = [
157158
]
158159
ignore_missing_imports = true
159160

161+
[[tool.mypy.overrides]]
162+
# mypy-protobuf codegen has some unused ignores.
163+
module = ["nidaqmx._stubs.*"]
164+
warn_unused_ignores = false
165+
160166
[tool.bandit]
161167
skips = [
162168
"B101", # assert_used

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
n_samples = 0
4040
%endif
4141
options = 0
42-
callback_method_ptr = ${callback_func_param.type}() # type: ignore # typeshed is missing no-argument constructor overload
42+
callback_method_ptr = ${callback_func_param.type}()
4343
callback_data = None
4444
%endif
4545

tests/acceptance/test_internationalization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from nidaqmx._lib import lib_importer, get_encoding_from_locale
8+
from nidaqmx._lib import get_encoding_from_locale, lib_importer
99
from nidaqmx.error_codes import DAQmxErrors
1010
from nidaqmx.errors import DaqError
1111
from nidaqmx.system import Device
@@ -63,7 +63,7 @@ def test___supported_encoding___logging_file_path___returns_assigned_value(
6363
):
6464
if _get_encoding(ai_task) not in supported_encodings:
6565
pytest.skip("requires compatible encoding")
66-
ai_task.in_stream.logging_file_path = file_path # type: ignore[assignment] # https://github.com/ni/nidaqmx-python/issues/613
66+
ai_task.in_stream.logging_file_path = file_path
6767

6868
assert ai_task.in_stream.logging_file_path == pathlib.Path(file_path)
6969

tests/component/task/test_in_stream_read_properties.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def test___ai_task___get_string_property___returns_default_value(ai_task: Task):
127127

128128

129129
def test___ai_task___set_string_property___returns_assigned_value(ai_task: Task):
130-
ai_task.in_stream.logging_file_path = "TestData.tdms" # type: ignore[assignment] # https://github.com/ni/nidaqmx-python/issues/613
130+
ai_task.in_stream.logging_file_path = "TestData.tdms"
131131

132132
assert ai_task.in_stream.logging_file_path == pathlib.Path("TestData.tdms")
133133

@@ -139,7 +139,7 @@ def test___ai_task___set_string_property_none___returns_default_value(ai_task: T
139139

140140

141141
def test___ai_task___reset_string_property___returns_default_value(ai_task: Task):
142-
ai_task.in_stream.logging_file_path = "TestData.tdms" # type: ignore[assignment] # https://github.com/ni/nidaqmx-python/issues/613
142+
ai_task.in_stream.logging_file_path = "TestData.tdms"
143143

144144
del ai_task.in_stream.logging_file_path
145145

tests/component/test_watchdog.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77

88
from nidaqmx.constants import WatchdogAOExpirState, WatchdogCOExpirState
99
from nidaqmx.system import Device
10-
from nidaqmx.system.watchdog import AOExpirationState, COExpirationState, WatchdogTask
10+
from nidaqmx.system.watchdog import (
11+
AOExpirationState,
12+
COExpirationState,
13+
ExpirationState,
14+
WatchdogTask,
15+
)
1116

1217

1318
def test___watchdog_task___cfg_watchdog_ao_expir_states___no_error(
@@ -129,8 +134,9 @@ def test___watchdog_expiration_states___set_nonexistent_property___raises_except
129134
)
130135
]
131136
watchdog_task.cfg_watchdog_ao_expir_states(expir_states)
137+
expir_state: ExpirationState = watchdog_task.expiration_states[
138+
sim_9263_device.ao_physical_chans[0].name
139+
]
132140

133141
with pytest.raises(AttributeError):
134-
watchdog_task.expiration_states[
135-
sim_9263_device.ao_physical_chans[0].name
136-
].nonexistent_property = "foo" # type: ignore[attr-defined]
142+
expir_state.nonexistent_property = "foo" # type: ignore[attr-defined]

tests/unit/test_grpc_time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def test___grpc_response_before_1970___convert_to_timestamp___succeeds(response_
120120
)
121121
def test___utc_datetime___convert_to_timestamp_with_dst___is_reversible(date):
122122
# we use a location that has daylight savings date change on the dates above
123-
target_timezone: ZoneInfo = ZoneInfo("America/Los_Angeles") # type: ignore # ZoneInfo is a concrete class that takes in abstract tzinfo
123+
target_timezone = ZoneInfo("America/Los_Angeles")
124124
astimezone_date = date.astimezone(target_timezone)
125125

126126
to_ts = grpc_time.convert_time_to_timestamp(date)

tests/unit/test_lib_time.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test___utc_datetime_before_1904___convert_to_timestamp___is_reversible(from_
9797
)
9898
def test___utc_datetime___convert_to_timestamp_with_dst___is_reversible(date):
9999
# we use a location that has daylight savings date change on the dates above
100-
target_timezone: ZoneInfo = ZoneInfo("America/Los_Angeles") # type: ignore # ZoneInfo is a concrete class that takes in abstract tzinfo
100+
target_timezone = ZoneInfo("America/Los_Angeles")
101101
astimezone_date = date.astimezone(target_timezone)
102102

103103
to_ts = LibTimestamp.from_datetime(date)

0 commit comments

Comments
 (0)