Comments (7)
I see, I misread the code.
However bool
(as documented) is right.
Returning int
is wrong, we don't use magic int
values in the Python API. A property like this would be bool
if possible, its own enum type if not.
from nimi-python.
It happens.
Thanks for considering it again. :)
from nimi-python.
Here is a list of the properties that are documented as bool
but are in fact int
in Python:
autorange
current_limit_autorange
current_level_autorange
voltage_limit_autorange
voltage_level_autorange
EDIT: I tested all of them in a similar fashion as the above test script provided when I opened the issue.
from nimi-python.
Hello,
In the code documentation, most of the "autorange"-related parameter are described as bool, which is wrong.
The correct type is int.
Looking at the nidcpower.Session
code, I see that the type of property autorange
is bool
, which matches documentation.
You may be thinking bool
is wrong because the NI-DCPower C API defines the attribute as ViInt32
. But while our Python and C APIs are very close matches, they do deviate in small specific ways enabled by the nature of the Python language. This is an example of that. Please check our Python API Design Guidelines for more detail.
Thanks for the feedback!
from nimi-python.
Hello,
I do not think that bool
is wrong because of the C API, but because Python tells me so. (See the pytest code example.)
The first link that you provided, which refers to nidcpower._SessionBase
in the session
module, proves that the documentation is wrong, as Python sees the returned type as an int
.
from nimi-python.
most of the "autorange"-related parameter are described as bool, which is wrong.
Were there other properties in the API that seem wrong?
from nimi-python.
Based on what @marcoskirsch has told me, we should have done something like this with an enum for each of these properties:
'IsolationState': {
'codegen_method': 'private',
'converted_value_to_enum_function_name': 'convert_to_isolation_state_enum',
'enum_to_converted_value_function_name': 'convert_from_isolation_state_enum',
'values': [
{
'converts_to_value': True,
'documentation': {
'description': 'The channel is disconnected from chassis ground.'
},
'name': 'NIDCPOWER_VAL_ISOLATED',
'value': 1128
},
{
'converts_to_value': False,
'documentation': {
'description': 'The channel is connected to chassis ground.'
},
'name': 'NIDCPOWER_VAL_NON_ISOLATED',
'value': 1129
}
]
},
Key points:
- Have a private enum that we convert to/from (in some or all cases that enum doesn't exist, even privately, for the Python API, I think, but does for the C API)
- For that enum:
- define
converted_value_to_enum_function_name
- define
enum_to_converted_value_function_name
- define
converts_to_value
for each value
- define
Before we make a change like this, we need to think through the implications and do some testing to confirm it's not a breaking change.
from nimi-python.
Related Issues (20)
- Repeated capability accessors return internal `_SessionBase` type HOT 2
- Incorrect documentation for the channel_name parameter of niFgen.Session HOT 2
- Add library stubs for use with mypy HOT 6
- Documentation is failing to build on Read the Docs due to the read_the_docs theme not being found.
- Unnecessary write access request when trying to read a property HOT 5
- Silently ignore and change value when passing minimum value to source_delay attribute in nidcpower HOT 4
- nidcpower.errors.DriverError: -1074097808: Could not load the dynamic library. HOT 2
- APIs allow repeated capabilities to access attributes and methods that don't support them HOT 6
- Github Actions Workflows should be updated to use Node.js 20 HOT 2
- Adopt use of Mend Renovate App to automatically update tooling and dependencies HOT 2
- Internal Test Suites do not report results of example testing HOT 1
- Using Python FGEN API to control PXIe-5413 signal generator works first time but fails after power cycling devices with error "-88717: No device by the given name was found" HOT 10
- Add support for Python 3.12 HOT 1
- Drop Python 3.9 support when it goes EOL
- codecov status badge is affected by coverage of unmerged PRs HOT 1
- Create a tool to help with version support changes
- nidcpower.errors.DriverError: -1074135040: IVI: Unrecoverable Failure. HOT 11
- Bypass NI cooling requirements HOT 1
- Cannot connect to a PXIe-4139 card located at some IP address HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nimi-python.