ni / ni/nimi-python

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

Open
#1,885 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
128
Forks
110
Avg merge
5d 14h
Merged PRs (30d)
10

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating _SessionBase.measure_multiple and its locally defined Measurement named tuple. Review how nidcpower exposes that type and reproduce the VS Code annotation behavior described in the issue. Done means List[nidcpower.Measurement] is recognized with typed elements and field access such as channel is no longer Any.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.