Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated capability accessors return internal _SessionBase type #2019

Open
bkeryan opened this issue Sep 22, 2023 · 2 comments
Open

Repeated capability accessors return internal _SessionBase type #2019

bkeryan opened this issue Sep 22, 2023 · 2 comments
Milestone

Comments

@bkeryan
Copy link
Contributor

bkeryan commented Sep 22, 2023

Description of issue

Repeated capability accessors like Session.channels and Session.instruments return a _SessionBase object. Clients that pass channel objects around may need to refer to this type in PEP 484 type hints.

Example: https://github.com/ni/measurementlink-python/blob/9bffe48c1c2da4777eeca0ca159b74bde724ead6/examples/output_voltage_measurement/measurement.py#L177

def _wait_for_source_complete_event(
    measurement_service: nims.MeasurementService,
    channels: nidcpower._SessionBase,
    cancellation_event: threading.Event,
) -> None: ...

The convention recommended in PEP8 and used by most Python code is that names with a single leading underscore are for internal use.

In general, public APIs ought to use public types.

System report

Not applicable.

Steps to reproduce issue

  1. Write a function that accepts a channel object (such as the linked example).
  2. Write PEP 484 type hints for this function.
@bkeryan
Copy link
Contributor Author

bkeryan commented Sep 22, 2023

BTW, providing public type aliases for Channel, Instrument, Pin, Site, etc. would be a relatively easy solution.

Channel = _SessionBase
Instrument = _SessionBase
...

@bkeryan
Copy link
Contributor Author

bkeryan commented Sep 22, 2023

Note that _SessionBase is in nidcpower.session and not aliased into nidcpower, so the example code above is incorrect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants