Skip to content

Commit 90d6064

Browse files
authored
mypy: Disallow untyped defs (#379)
* service: Fix grpc_servicer type hints ni_measurementlink_service\_internal\grpc_servicer.py:168: error: Function is missing a return type annotation [no-untyped-def] ni_measurementlink_service\_internal\grpc_servicer.py:311: error: Function is missing a return type annotation [no-untyped-def] * service: Fix a serializer type hint ni_measurementlink_service\_internal\parameter\serializer.py:113: error: Function is missing a return type annotation [no-untyped-def] * service: Add a missing cast * service: More grpc_servicer type hints * service: More type hints * pyproject.toml: Enable mypy --disable-untyped-defs * generator: Add missing type hints ni_measurementlink_generator\template.py:14: error: Function is missing a type annotation for one or more arguments [no-untyped-def] ni_measurementlink_generator\template.py:27: error: Function is missing a return type annotation [no-untyped-def] ni_measurementlink_generator\template.py:27: error: Function is missing a type annotation for one or more arguments [no-untyped-def] * generator: Disallow untyped defs * examples: Add missing _helpers.py type hints _helpers.py:42: error: Function is missing a type annotation for one or more arguments [no-untyped-def] _helpers.py:184: error: Function is missing a return type annotation [no-untyped-def] * examples: Enable mypy --disallow-untyped-defs and fix errors * tests: Allow untyped defs :( * generator: Fix lint errors * generator: Fix test errors caused by rerunning black * examples: Only type alias outputs when needed for yield + return
1 parent f8321f1 commit 90d6064

52 files changed

Lines changed: 155 additions & 98 deletions

File tree

Some content is hidden

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

examples/nidaqmx_analog_input/_helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ServiceOptions(NamedTuple):
3939
use_simulation: bool = False
4040

4141

42-
def get_service_options(**kwargs) -> ServiceOptions:
42+
def get_service_options(**kwargs: Any) -> ServiceOptions:
4343
"""Get service options from keyword arguments."""
4444
return ServiceOptions(
4545
use_grpc_device=kwargs.get("use_grpc_device", False),
@@ -81,7 +81,7 @@ def update_pin_map(self, pin_map_path: str) -> str:
8181
class GrpcChannelPoolHelper(GrpcChannelPool):
8282
"""Class that manages gRPC channel lifetimes."""
8383

84-
def __init__(self):
84+
def __init__(self) -> None:
8585
"""Initialize the GrpcChannelPool object."""
8686
super().__init__()
8787
self._discovery_client = DiscoveryClient()
@@ -181,7 +181,7 @@ def resolve_file_path(self, file_path: str) -> str:
181181
return absolute_path
182182

183183

184-
def configure_logging(verbosity: int):
184+
def configure_logging(verbosity: int) -> None:
185185
"""Configure logging for this process."""
186186
if verbosity > 1:
187187
level = logging.DEBUG

examples/nidaqmx_analog_input/_nidaqmx_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
def create_task(
1212
session_info: nims.session_management.SessionInformation,
1313
session_grpc_channel: Optional[grpc.Channel] = None,
14-
initialization_behavior=nidaqmx.SessionInitializationBehavior.AUTO,
14+
initialization_behavior: nidaqmx.SessionInitializationBehavior = nidaqmx.SessionInitializationBehavior.AUTO,
1515
) -> nidaqmx.Task:
1616
"""Create daqmx task based on reserved session and grpc channel."""
1717
session_kwargs = {}

examples/nidaqmx_analog_input/measurement.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import pathlib
55
import sys
6-
from typing import List, Optional, Tuple
6+
from typing import Any, List, Optional, Tuple
77

88
import click
99
import nidaqmx
@@ -95,7 +95,7 @@ def cancel_callback() -> None:
9595
return (voltage_values,)
9696

9797

98-
def _log_measured_values(samples, max_samples_to_display=5):
98+
def _log_measured_values(samples: List[float], max_samples_to_display: int = 5) -> None:
9999
"""Log the measured values."""
100100
if len(samples) > max_samples_to_display:
101101
for index, value in enumerate(samples[0 : max_samples_to_display - 1]):
@@ -110,7 +110,7 @@ def _log_measured_values(samples, max_samples_to_display=5):
110110
@click.command
111111
@verbosity_option
112112
@grpc_device_options
113-
def main(verbosity: int, **kwargs):
113+
def main(verbosity: int, **kwargs: Any) -> None:
114114
"""Perform a finite analog input measurement with NI-DAQmx."""
115115
configure_logging(verbosity)
116116
global service_options

examples/nidaqmx_analog_input/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ grpc-stubs = "^1.53"
2121
requires = ["poetry-core>=1.2.0"]
2222
build-backend = "poetry.core.masonry.api"
2323

24+
[tool.mypy]
25+
disallow_untyped_defs = true
26+
2427
[[tool.mypy.overrides]]
2528
module = [
2629
"nidaqmx.*",

examples/nidcpower_source_dc_voltage/_helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ServiceOptions(NamedTuple):
3939
use_simulation: bool = False
4040

4141

42-
def get_service_options(**kwargs) -> ServiceOptions:
42+
def get_service_options(**kwargs: Any) -> ServiceOptions:
4343
"""Get service options from keyword arguments."""
4444
return ServiceOptions(
4545
use_grpc_device=kwargs.get("use_grpc_device", False),
@@ -81,7 +81,7 @@ def update_pin_map(self, pin_map_path: str) -> str:
8181
class GrpcChannelPoolHelper(GrpcChannelPool):
8282
"""Class that manages gRPC channel lifetimes."""
8383

84-
def __init__(self):
84+
def __init__(self) -> None:
8585
"""Initialize the GrpcChannelPool object."""
8686
super().__init__()
8787
self._discovery_client = DiscoveryClient()
@@ -181,7 +181,7 @@ def resolve_file_path(self, file_path: str) -> str:
181181
return absolute_path
182182

183183

184-
def configure_logging(verbosity: int):
184+
def configure_logging(verbosity: int) -> None:
185185
"""Configure logging for this process."""
186186
if verbosity > 1:
187187
level = logging.DEBUG

examples/nidcpower_source_dc_voltage/_nidcpower_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
def create_session(
1313
session_info: nims.session_management.SessionInformation,
1414
session_grpc_channel: Optional[grpc.Channel] = None,
15-
initialization_behavior=nidcpower.SessionInitializationBehavior.AUTO,
15+
initialization_behavior: nidcpower.SessionInitializationBehavior = nidcpower.SessionInitializationBehavior.AUTO,
1616
) -> nidcpower.Session:
1717
"""Create driver session based on reserved session and grpc channel."""
1818
options: Dict[str, Any] = {}

examples/nidcpower_source_dc_voltage/measurement.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import sys
66
import threading
77
import time
8-
from typing import Iterable, List, Tuple
8+
from typing import Any, Iterable, List, Tuple
99

1010
import click
1111
import grpc
@@ -170,7 +170,7 @@ def _log_measured_values(
170170
@verbosity_option
171171
@grpc_device_options
172172
@use_simulation_option(default=USE_SIMULATION)
173-
def main(verbosity: int, **kwargs) -> None:
173+
def main(verbosity: int, **kwargs: Any) -> None:
174174
"""Source and measure a DC voltage with an NI SMU."""
175175
configure_logging(verbosity)
176176

examples/nidcpower_source_dc_voltage/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ grpc-stubs = "^1.53"
2222
requires = ["poetry-core>=1.2.0"]
2323
build-backend = "poetry.core.masonry.api"
2424

25+
[tool.mypy]
26+
disallow_untyped_defs = true
27+
2528
[[tool.mypy.overrides]]
2629
module = [
2730
"hightime.*",

examples/nidigital_spi/_helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ServiceOptions(NamedTuple):
3939
use_simulation: bool = False
4040

4141

42-
def get_service_options(**kwargs) -> ServiceOptions:
42+
def get_service_options(**kwargs: Any) -> ServiceOptions:
4343
"""Get service options from keyword arguments."""
4444
return ServiceOptions(
4545
use_grpc_device=kwargs.get("use_grpc_device", False),
@@ -81,7 +81,7 @@ def update_pin_map(self, pin_map_path: str) -> str:
8181
class GrpcChannelPoolHelper(GrpcChannelPool):
8282
"""Class that manages gRPC channel lifetimes."""
8383

84-
def __init__(self):
84+
def __init__(self) -> None:
8585
"""Initialize the GrpcChannelPool object."""
8686
super().__init__()
8787
self._discovery_client = DiscoveryClient()
@@ -181,7 +181,7 @@ def resolve_file_path(self, file_path: str) -> str:
181181
return absolute_path
182182

183183

184-
def configure_logging(verbosity: int):
184+
def configure_logging(verbosity: int) -> None:
185185
"""Configure logging for this process."""
186186
if verbosity > 1:
187187
level = logging.DEBUG

examples/nidigital_spi/_nidigital_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
def create_session(
1313
session_info: nims.session_management.SessionInformation,
1414
session_grpc_channel: Optional[grpc.Channel] = None,
15-
initialization_behavior=nidigital.SessionInitializationBehavior.AUTO,
15+
initialization_behavior: nidigital.SessionInitializationBehavior = nidigital.SessionInitializationBehavior.AUTO,
1616
) -> nidigital.Session:
1717
"""Create driver session based on reserved session and grpc channel."""
1818
options: Dict[str, Any] = {}

0 commit comments

Comments
 (0)