Skip to content

Commit

Permalink
mypy: Disallow untyped defs (#379)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bkeryan authored Sep 18, 2023
1 parent f8321f1 commit 90d6064
Show file tree
Hide file tree
Showing 52 changed files with 155 additions and 98 deletions.
6 changes: 3 additions & 3 deletions examples/nidaqmx_analog_input/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ServiceOptions(NamedTuple):
use_simulation: bool = False


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

def __init__(self):
def __init__(self) -> None:
"""Initialize the GrpcChannelPool object."""
super().__init__()
self._discovery_client = DiscoveryClient()
Expand Down Expand Up @@ -181,7 +181,7 @@ def resolve_file_path(self, file_path: str) -> str:
return absolute_path


def configure_logging(verbosity: int):
def configure_logging(verbosity: int) -> None:
"""Configure logging for this process."""
if verbosity > 1:
level = logging.DEBUG
Expand Down
2 changes: 1 addition & 1 deletion examples/nidaqmx_analog_input/_nidaqmx_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def create_task(
session_info: nims.session_management.SessionInformation,
session_grpc_channel: Optional[grpc.Channel] = None,
initialization_behavior=nidaqmx.SessionInitializationBehavior.AUTO,
initialization_behavior: nidaqmx.SessionInitializationBehavior = nidaqmx.SessionInitializationBehavior.AUTO,
) -> nidaqmx.Task:
"""Create daqmx task based on reserved session and grpc channel."""
session_kwargs = {}
Expand Down
6 changes: 3 additions & 3 deletions examples/nidaqmx_analog_input/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import pathlib
import sys
from typing import List, Optional, Tuple
from typing import Any, List, Optional, Tuple

import click
import nidaqmx
Expand Down Expand Up @@ -95,7 +95,7 @@ def cancel_callback() -> None:
return (voltage_values,)


def _log_measured_values(samples, max_samples_to_display=5):
def _log_measured_values(samples: List[float], max_samples_to_display: int = 5) -> None:
"""Log the measured values."""
if len(samples) > max_samples_to_display:
for index, value in enumerate(samples[0 : max_samples_to_display - 1]):
Expand All @@ -110,7 +110,7 @@ def _log_measured_values(samples, max_samples_to_display=5):
@click.command
@verbosity_option
@grpc_device_options
def main(verbosity: int, **kwargs):
def main(verbosity: int, **kwargs: Any) -> None:
"""Perform a finite analog input measurement with NI-DAQmx."""
configure_logging(verbosity)
global service_options
Expand Down
3 changes: 3 additions & 0 deletions examples/nidaqmx_analog_input/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ grpc-stubs = "^1.53"
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
disallow_untyped_defs = true

[[tool.mypy.overrides]]
module = [
"nidaqmx.*",
Expand Down
6 changes: 3 additions & 3 deletions examples/nidcpower_source_dc_voltage/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ServiceOptions(NamedTuple):
use_simulation: bool = False


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

def __init__(self):
def __init__(self) -> None:
"""Initialize the GrpcChannelPool object."""
super().__init__()
self._discovery_client = DiscoveryClient()
Expand Down Expand Up @@ -181,7 +181,7 @@ def resolve_file_path(self, file_path: str) -> str:
return absolute_path


def configure_logging(verbosity: int):
def configure_logging(verbosity: int) -> None:
"""Configure logging for this process."""
if verbosity > 1:
level = logging.DEBUG
Expand Down
2 changes: 1 addition & 1 deletion examples/nidcpower_source_dc_voltage/_nidcpower_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def create_session(
session_info: nims.session_management.SessionInformation,
session_grpc_channel: Optional[grpc.Channel] = None,
initialization_behavior=nidcpower.SessionInitializationBehavior.AUTO,
initialization_behavior: nidcpower.SessionInitializationBehavior = nidcpower.SessionInitializationBehavior.AUTO,
) -> nidcpower.Session:
"""Create driver session based on reserved session and grpc channel."""
options: Dict[str, Any] = {}
Expand Down
4 changes: 2 additions & 2 deletions examples/nidcpower_source_dc_voltage/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import threading
import time
from typing import Iterable, List, Tuple
from typing import Any, Iterable, List, Tuple

import click
import grpc
Expand Down Expand Up @@ -170,7 +170,7 @@ def _log_measured_values(
@verbosity_option
@grpc_device_options
@use_simulation_option(default=USE_SIMULATION)
def main(verbosity: int, **kwargs) -> None:
def main(verbosity: int, **kwargs: Any) -> None:
"""Source and measure a DC voltage with an NI SMU."""
configure_logging(verbosity)

Expand Down
3 changes: 3 additions & 0 deletions examples/nidcpower_source_dc_voltage/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ grpc-stubs = "^1.53"
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
disallow_untyped_defs = true

[[tool.mypy.overrides]]
module = [
"hightime.*",
Expand Down
6 changes: 3 additions & 3 deletions examples/nidigital_spi/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ServiceOptions(NamedTuple):
use_simulation: bool = False


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

def __init__(self):
def __init__(self) -> None:
"""Initialize the GrpcChannelPool object."""
super().__init__()
self._discovery_client = DiscoveryClient()
Expand Down Expand Up @@ -181,7 +181,7 @@ def resolve_file_path(self, file_path: str) -> str:
return absolute_path


def configure_logging(verbosity: int):
def configure_logging(verbosity: int) -> None:
"""Configure logging for this process."""
if verbosity > 1:
level = logging.DEBUG
Expand Down
2 changes: 1 addition & 1 deletion examples/nidigital_spi/_nidigital_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def create_session(
session_info: nims.session_management.SessionInformation,
session_grpc_channel: Optional[grpc.Channel] = None,
initialization_behavior=nidigital.SessionInitializationBehavior.AUTO,
initialization_behavior: nidigital.SessionInitializationBehavior = nidigital.SessionInitializationBehavior.AUTO,
) -> nidigital.Session:
"""Create driver session based on reserved session and grpc channel."""
options: Dict[str, Any] = {}
Expand Down
4 changes: 2 additions & 2 deletions examples/nidigital_spi/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import pathlib
import sys
from typing import Iterable, Tuple, Union
from typing import Any, Iterable, Tuple, Union

import click
import nidigital
Expand Down Expand Up @@ -121,7 +121,7 @@ def _resolve_relative_path(
@verbosity_option
@grpc_device_options
@use_simulation_option(default=USE_SIMULATION)
def main(verbosity: int, **kwargs) -> None:
def main(verbosity: int, **kwargs: Any) -> None:
"""Test a SPI device using an NI Digital Pattern instrument."""
configure_logging(verbosity)
global service_options
Expand Down
3 changes: 3 additions & 0 deletions examples/nidigital_spi/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ grpc-stubs = "^1.53"
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
disallow_untyped_defs = true

[[tool.mypy.overrides]]
module = [
"nidigital.*",
Expand Down
6 changes: 3 additions & 3 deletions examples/nidmm_measurement/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ServiceOptions(NamedTuple):
use_simulation: bool = False


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

def __init__(self):
def __init__(self) -> None:
"""Initialize the GrpcChannelPool object."""
super().__init__()
self._discovery_client = DiscoveryClient()
Expand Down Expand Up @@ -181,7 +181,7 @@ def resolve_file_path(self, file_path: str) -> str:
return absolute_path


def configure_logging(verbosity: int):
def configure_logging(verbosity: int) -> None:
"""Configure logging for this process."""
if verbosity > 1:
level = logging.DEBUG
Expand Down
2 changes: 1 addition & 1 deletion examples/nidmm_measurement/_nidmm_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def create_session(
session_info: nims.session_management.SessionInformation,
session_grpc_channel: Optional[grpc.Channel] = None,
initialization_behavior=nidmm.SessionInitializationBehavior.AUTO,
initialization_behavior: nidmm.SessionInitializationBehavior = nidmm.SessionInitializationBehavior.AUTO,
) -> nidmm.Session:
"""Create driver session based on reserved session and grpc channel."""
options: Dict[str, Any] = {}
Expand Down
4 changes: 2 additions & 2 deletions examples/nidmm_measurement/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pathlib
import sys
from enum import Enum
from typing import Tuple
from typing import Any, Tuple

import click
import nidmm
Expand Down Expand Up @@ -122,7 +122,7 @@ def measure(
@verbosity_option
@grpc_device_options
@use_simulation_option(default=USE_SIMULATION)
def main(verbosity: int, **kwargs) -> None:
def main(verbosity: int, **kwargs: Any) -> None:
"""Perform a measurement using an NI DMM."""
configure_logging(verbosity)
global service_options
Expand Down
3 changes: 3 additions & 0 deletions examples/nidmm_measurement/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ grpc-stubs = "^1.53"
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
disallow_untyped_defs = true

[[tool.mypy.overrides]]
module = [
"nidmm.*",
Expand Down
6 changes: 3 additions & 3 deletions examples/nifgen_standard_function/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ServiceOptions(NamedTuple):
use_simulation: bool = False


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

def __init__(self):
def __init__(self) -> None:
"""Initialize the GrpcChannelPool object."""
super().__init__()
self._discovery_client = DiscoveryClient()
Expand Down Expand Up @@ -181,7 +181,7 @@ def resolve_file_path(self, file_path: str) -> str:
return absolute_path


def configure_logging(verbosity: int):
def configure_logging(verbosity: int) -> None:
"""Configure logging for this process."""
if verbosity > 1:
level = logging.DEBUG
Expand Down
2 changes: 1 addition & 1 deletion examples/nifgen_standard_function/_nifgen_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def create_session(
session_info: nims.session_management.SessionInformation,
session_grpc_channel: Optional[grpc.Channel] = None,
initialization_behavior=nifgen.SessionInitializationBehavior.AUTO,
initialization_behavior: nifgen.SessionInitializationBehavior = nifgen.SessionInitializationBehavior.AUTO,
) -> nifgen.Session:
"""Create driver session based on reserved session and grpc channel."""
options: Dict[str, Any] = {}
Expand Down
4 changes: 2 additions & 2 deletions examples/nifgen_standard_function/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import threading
import time
from enum import Enum
from typing import Tuple
from typing import Any, Tuple

import click
import grpc
Expand Down Expand Up @@ -170,7 +170,7 @@ def measure(
@verbosity_option
@grpc_device_options
@use_simulation_option(default=USE_SIMULATION)
def main(verbosity: int, **kwargs) -> None:
def main(verbosity: int, **kwargs: Any) -> None:
"""Generate a standard function waveform using an NI waveform generator."""
configure_logging(verbosity)
global service_options
Expand Down
3 changes: 3 additions & 0 deletions examples/nifgen_standard_function/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ grpc-stubs = "^1.53"
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
disallow_untyped_defs = true

[[tool.mypy.overrides]]
module = [
"hightime.*",
Expand Down
6 changes: 3 additions & 3 deletions examples/niscope_acquire_waveform/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ServiceOptions(NamedTuple):
use_simulation: bool = False


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

def __init__(self):
def __init__(self) -> None:
"""Initialize the GrpcChannelPool object."""
super().__init__()
self._discovery_client = DiscoveryClient()
Expand Down Expand Up @@ -181,7 +181,7 @@ def resolve_file_path(self, file_path: str) -> str:
return absolute_path


def configure_logging(verbosity: int):
def configure_logging(verbosity: int) -> None:
"""Configure logging for this process."""
if verbosity > 1:
level = logging.DEBUG
Expand Down
2 changes: 1 addition & 1 deletion examples/niscope_acquire_waveform/_niscope_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def create_session(
session_info: nims.session_management.SessionInformation,
session_grpc_channel: Optional[grpc.Channel] = None,
initialization_behavior=niscope.SessionInitializationBehavior.AUTO,
initialization_behavior: niscope.SessionInitializationBehavior = niscope.SessionInitializationBehavior.AUTO,
) -> niscope.Session:
"""Create driver session based on reserved session and grpc channel."""
options: Dict[str, Any] = {}
Expand Down
4 changes: 2 additions & 2 deletions examples/niscope_acquire_waveform/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sys
import threading
import time
from typing import List, Tuple
from typing import Any, List, Tuple

import click
import grpc
Expand Down Expand Up @@ -183,7 +183,7 @@ def measure(
@verbosity_option
@grpc_device_options
@use_simulation_option(default=USE_SIMULATION)
def main(verbosity: int, **kwargs) -> None:
def main(verbosity: int, **kwargs: Any) -> None:
"""Acquire a waveform using an NI oscilloscope."""
configure_logging(verbosity)
global service_options
Expand Down
3 changes: 3 additions & 0 deletions examples/niscope_acquire_waveform/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ grpc-stubs = "^1.53"
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"

[tool.mypy]
disallow_untyped_defs = true

[[tool.mypy.overrides]]
module = [
"niscope.*",
Expand Down
Loading

0 comments on commit 90d6064

Please sign in to comment.