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

Boolean comparison on undefined leafrefs #361

Open
ianbarrere opened this issue Oct 18, 2024 · 0 comments
Open

Boolean comparison on undefined leafrefs #361

ianbarrere opened this issue Oct 18, 2024 · 0 comments

Comments

@ianbarrere
Copy link

ianbarrere commented Oct 18, 2024

Hello,

It seems that some values, like leafrefs which aren't defined, end up as a False sort of thing, but represented as a YANGBaseClass object. Trying to determine in python whether this value is referenced to something real or not is difficult, since python thinks something is there, but the thing is a False YANGBaseClass. The workaround I'm using for this is to string cast the object, which results in "False", and then compare that with "False". Seems like a silly a way to do it, so I'm wondering if there is a better way, like an actual boolean attribute on the YANGBaseClass, perhaps. Or maybe this is unintended behavior of undefined leafrefs, I'm not sure. Here is a basic reproduction:

module leafref {
  namespace "http://example.com/leafref";
  prefix "leafref";

  leaf-list test {
    type string;
  }
  container leafref-test {
    leaf test {
      type leafref {
        path "/test";
      }
    }
  }
}

And some code:

>>> import leafref
>>> binding = leafref.leafref()
>>> binding.get()
{'test': [], 'leafref-test': {'test': False}}
>>> binding.leafref_test.test
False
>>> type(binding.leafref_test.test)
<class 'pyangbind.lib.yangtypes.YANGDynClass.<locals>.YANGBaseClass'>
>>> binding.leafref_test.test is False
False
>>> str(binding.leafref_test.test) == "False"
True
>>>
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

1 participant