Skip to content

Boolean comparison on undefined leafrefs #361

Description

@ianbarrere

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
>>>

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions