-
Notifications
You must be signed in to change notification settings - Fork 93
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
Disallow repeated capability on session #883
Conversation
CHANGELOG.md
Outdated
@@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file. | |||
* #### Added | |||
* #### Changed | |||
* #### Removed | |||
* Explicitly disallow using a repeated capability on Session. `session['0'].vertical_range = 1.0` will no longer work. Instead use `session.channels['0'].vertical_range = 1.0` - [#853](https://github.com/ni/nimi-python/issues/853) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in example snippets we should show the use of indices with numbers.
Meaning: session[0].vertical_range = 1.0
as opposed to session['0'].vertical_range = 1.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
@@ -190,6 +190,9 @@ constructor_params = helper.filter_parameters(init_function, helper.ParameterUsa | |||
raise AttributeError("'{0}' object has no attribute '{1}'".format(type(self).__name__, key)) | |||
object.__setattr__(self, key, value) | |||
|
|||
def __getitem__(self, key): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? When you try to index a class that doesn't support it, the error is:
TypeError: 'Foo' object does not support indexing
We wouldn't want this to be different. Let's let Python do its thing.
If you think the text in the exception is a good enough reason (I'm not convinced) then let's make it really useful:
- raise TypeError
- text should say `'Session' object does not support indexing. XXX
- XXX should be something that talks about the repeated capability containers for the class. The magic of codegen! (or we could at runtime figure it out)
Regardless, I'm not sure it's worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is needed. Without it, it does not error when using session[0]
. I'm not sure it actually works, but it doesn't error.
- Changed to
TypeError
- Text now says "'Session' object does not support indexing. You should use the applicable repeated capabilities container(s): {}"
- where {} is the list of containers supported by that driver
try: | ||
session['100'].read_write_double = 5.0 | ||
assert False | ||
except AttributeError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeError
What does this Pull Request accomplish?
session[0].vertical_range = 1.0
will no longer work. Instead usesession.channels[0].vertical_range = 1.0
List issues fixed by this Pull Request below, if any.
What testing has been done?