GithubHelp home page GithubHelp logo

Comments (2)

robshakir avatar robshakir commented on May 17, 2024

I can't see any case where this can be valid. In general, pyangbind will try to cast the input to the type that is expected, so for example, if we have the following module:

module "test" {
    prefix "t";
    namespace "http://rob.sh/yang/t";

    container test {
        leaf number {
            type uint32;
        }

        leaf number-range {
            type uint32 {
                range "1..max";
            }
        }
    }
}

Then, we can do:

>>> t.test.number = False
>>> t.test.number = 0

Since int(False) == 0, however:

>>> t.test.number = None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tmp.py", line 67, in _set_number
    raise ValueError("""number must be of a type compatible with base=np.uint32, is_leaf=True, yang_name="number", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True""")
ValueError: number must be of a type compatible with base=np.uint32, is_leaf=True, yang_name="number", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True
>>> int(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: int() argument must be a string or a number, not 'NoneType'

You cannot set an int to None because NoneType cannot be cast to int. So, even without the range, I don't think that this is valid. The reason that this is relevant is because the following JSON:

{
    "value": null
}

is loaded by Python's json library to use None rather than null:

>>> import json
>>> j = json.load(open("test.json", 'r'))
>>> print j
{u'value': None}

In your specific case, this isn't ever valid though - because if None/null were an integer value then it would be zero - which is outside of the 1..max range. With a normal leaf of this nature, one still get the error when one tries to set the value to 0:

>>> t.test.number_range = 0
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tmp.py", line 93, in _set_number_range
    raise ValueError("""number_range must be of a type compatible with base=RestrictedClassType(base_type=np.uint32, restriction_dict={'range': [u'1..max']}), is_leaf=True, yang_name="number-range", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True""")
ValueError: number_range must be of a type compatible with base=RestrictedClassType(base_type=np.uint32, restriction_dict={'range': [u'1..max']}), is_leaf=True, yang_name="number-range", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True
>>> t.test.number_range = 1

So, I'd say that your input JSON is not valid.

r.

from pyangbind.

mpainenz avatar mpainenz commented on May 17, 2024

OK Rob, thanks for clarifying, that all seems fine to me.

Much appreciated,
Mark

from pyangbind.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.