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

Disallow repeated capability on session #883

Merged
merged 12 commits into from
Jun 4, 2018
Merged

Disallow repeated capability on session #883

merged 12 commits into from
Jun 4, 2018

Conversation

texasaggie97-zz
Copy link
Contributor

@texasaggie97-zz texasaggie97-zz commented May 30, 2018

  • This contribution adheres to CONTRIBUTING.md.
  • I've updated CHANGELOG.md if applicable.
  • I've added tests applicable for this pull request

What does this Pull Request accomplish?

  • Disallow repeated capability on session
  • 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

List issues fixed by this Pull Request below, if any.

What testing has been done?

  • Unit
  • System

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)
Copy link
Member

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

Copy link
Contributor Author

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):
Copy link
Member

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.

Copy link
Contributor Author

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeError

@texasaggie97-zz texasaggie97-zz dismissed marcoskirsch’s stale review June 4, 2018 15:50

Comments addressed

@marcoskirsch marcoskirsch merged commit b985275 into master Jun 4, 2018
@marcoskirsch marcoskirsch deleted the bug853 branch June 4, 2018 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Directly indexing the session rather than the container works.
2 participants