ni / ni/nimi-python

Calling Session method/property with repeated capability when it doesn't support it raises inscrutable error

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

Nobody has claimed this yet.

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

Description

Description of issue

This is a usability problem that was uncovered by looking into #960 but is larger than just nifgen.Session.delete_waveform() so I am opening a separate issue.

This is a usability/error reporting problem. In the nimi-python APIs, the way you call a method on a specific repeated capability (like a channel) is as follows:

my_session.channels[3].foo()

But not all methods/properties support repeated capabilities. Take for instance method niscope.Session.auto_setup() which cannot be called on specific channels and when you do you get the following:

Traceback (most recent call last):
  File "p:\temp\issue.py", line 4, in <module>
    session.channels[0].auto_setup()
AttributeError: '_SessionBase' object has no attribute 'auto_setup'

The user should be getting an error that makes sense and gives guidance on what the mistake is and how to fix it. It should not "leak" an internal class _SessionBase.

System report
Z:\>  python -c "import niscope; niscope.print_diagnostic_information()"
OS:
    Name:      Windows
    Version:   10.0.18362
    Bits:      64
Driver:
    Name:      NI-SCOPE
    Version:   19.1.0.49152
Module:
    Name:      niscope
    Version:   1.1.5
Python:
    Version:   3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]
    Bits:      64
    Is_Venv:   False
    Installed Packages:
        virtualenv==20.0.4
        tox==3.14.5
        toml==0.10.0
        six==1.14.0
        setuptools==41.2.0
        pyparsing==2.4.6
        py==1.8.1
        pluggy==0.13.1
        pip==20.0.2
        packaging==20.1
        nitclk==0.3.1
        niscope==1.1.5
        filelock==3.0.12
        distlib==0.3.0
        colorama==0.4.3
        appdirs==1.4.3
Steps to reproduce issue
import niscope

with niscope.Session('FakeDevice', False, True, 'Simulate=1, DriverSetup=Model:5164; BoardType:PXIe') as session:
    session.channels[0].auto_setup()  # auto_setup() is not channel-based!

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 reproducing the issue through niscope.Session and session.channels[0].auto_setup(), then trace the repeated-capability dispatch that exposes _SessionBase. Done means unsupported channel calls raise a clear user-facing error explaining that auto_setup() is not channel-based and how to call it correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
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.