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

Fixes #179: Ensure uniqueness in leaf-list #200

Merged
merged 3 commits into from
May 16, 2018

Conversation

tarkatronic
Copy link
Collaborator

@tarkatronic tarkatronic commented May 15, 2018

Fixes #179

I couldn't use the set() type directly due to the fact they do not maintain order. So instead, I've added a unique=True option, along with a uniqueness check on value assignments to TypedList.

@codecov
Copy link

codecov bot commented May 15, 2018

Codecov Report

Merging #200 into master will decrease coverage by 2.91%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #200      +/-   ##
==========================================
- Coverage   73.11%   70.19%   -2.92%     
==========================================
  Files           7        7              
  Lines        1767     1661     -106     
  Branches      559      459     -100     
==========================================
- Hits         1292     1166     -126     
- Misses        353      369      +16     
- Partials      122      126       +4
Impacted Files Coverage Δ
pyangbind/lib/yangtypes.py 83.27% <100%> (+0.08%) ⬆️
pyangbind/lib/serialise.py 73.33% <0%> (-10.5%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a3694e5...2f6ec57. Read the comment docs.

@@ -377,19 +377,25 @@ class TypedList(collections.MutableSequence):
_list = list()

def __init__(self, *args, **kwargs):
self._unique = kwargs.pop('unique', False)
Copy link
Owner

Choose a reason for hiding this comment

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

Is there ever a scenario that we expect that a list is not unique? If not, it might be best to make this flag work the other way around such that we have something that says to skip the uniqueness check?

@@ -844,7 +844,7 @@ def get_children(ctx, fd, i_children, module, parent, path=str(),
# TypedList (see lib.yangtypes) with a particular set of types allowed.
class_str["name"] = "__%s" % (i["name"])
class_str["type"] = "YANGDynClass"
class_str["arg"] = "base="
class_str["arg"] = "unique=True, base="
Copy link
Owner

Choose a reason for hiding this comment

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

Having the unique the other way around in TypedListType would mean that we could avoid this in the generated code?

Copy link
Owner

@robshakir robshakir left a comment

Choose a reason for hiding this comment

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

Approving based on the comment -- apologies for flip-flopping on this, but the review discussion was useful for me.

Thanks again for the changes.

@@ -377,7 +377,7 @@ class TypedList(collections.MutableSequence):
_list = list()

def __init__(self, *args, **kwargs):
self._unique = kwargs.pop('unique', False)
self._unique = kwargs.pop('unique', True)
Copy link
Owner

Choose a reason for hiding this comment

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

Per the comments in Slack. I'm a little torn on this one.

If we make the default here True, then we'll end up saying that if existing consumers just upgrade pyangbind module from PyPi, but don't regenerate bindings, then existing code that expects this to be the previous state will end up being broken.

Sorry for the hassle, but I think requiring regenerating bindings such that the feature is turned on as you'd had this originally is safer to allow consumers to choose when to enable this.

Copy link
Owner

@robshakir robshakir left a comment

Choose a reason for hiding this comment

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

Actually -- sorry, looking again -- can you look at why the coverage dived by 10% on lib/serialise.py?

Copy link
Owner

@robshakir robshakir left a comment

Choose a reason for hiding this comment

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

@tarkatronic reverted the commit with the outstanding comments in. LGTM!

@robshakir robshakir merged commit 166ae1b into robshakir:master May 16, 2018
@tarkatronic tarkatronic deleted the issue_179 branch May 16, 2018 16:50
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

Successfully merging this pull request may close these issues.

3 participants