nimi-python icon indicating copy to clipboard operation
nimi-python copied to clipboard

NI-DCPower: `Measurement` named tuple does not work with type annotations

Open bkeryan opened this issue 2 years ago • 0 comments

Description of issue

Some of the ni-measurementlink-service examples use type annotations like typing.List[nidcpower.Measurement], but VS Code treats the list elements as typing.Any and doesn't auto-complete field accesses. I don't think this is causing any mypy failures.

There are a couple of reasons why the Measurement named tuple doesn't work with type annotations:

  • Measurement is defined in the body of _SessionBase.measure_multiple, not as a module-scoped type.
  • Measurement is defined using namedtuple and not typing.NamedTuple.

System report

OS:
    Name:      Windows
    Version:   10.0.19045
    Bits:      64
Driver:
    Name:      NI-DCPower
    Version:   22.8.0
Module:
    Name:      nidcpower
    Version:   1.4.3
Python:
    Version:   3.9.13 (tags/v3.9.13:6de2ca5, May 17 2022, 16:36:42) [MSC v.1929 64 bit (AMD64)]
    Bits:      64
    Is_Venv:   True
    Installed Packages:
        pywin32==303
        setuptools==65.3.0
        pip==22.2.2
        click==8.1.3
        protobuf==4.21.12
        grpcio==1.51.1
        nidcpower==1.4.3
        wheel==0.37.1
        ni-measurementlink-service==0.12.0
        colorama==0.4.6
        hightime==0.2.1

Steps to reproduce issue

  1. Open a typing-aware editor such as VS Code and set its interpreter to a venv that has nidcpower installed.
  2. Create or edit a .py file with import nidcpower at the top.
  3. Add measured_values: List[nidcpower.Measurement] = [].
  4. Hover over measured_values. The tooltip should say something like (variable) measured_values: list[nidcpower.Measurement], but it says (variable) measured_values: list.
  5. Add measured_values[0].channel on a separate line.
  6. However over channel. The tooltip should say channel: str but it says channel: Any.

bkeryan avatar Jan 06 '23 20:01 bkeryan