Cottonwood-Technology / ValidX

Fast, powerful, and flexible validator with sane syntax.
BSD 2-Clause "Simplified" License
20 stars 4 forks source link

Cloning Const(False) fails #19

Closed draggeta closed 1 year ago

draggeta commented 1 year ago

When cloning a Const(False):

import validx.py

a = validx.py.Const(False)
a.clone()

I get an error:

Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "c:\git\parsing\.venv\lib\site-packages\validx\py\abstract.py", line 226, in clone
    return self.load(self.dump(), update, unset, **kw)
  File "c:\git\parsing\.venv\lib\site-packages\validx\py\abstract.py", line 196, in load
    return _load_recurcive(params, _update, _unset)
  File "c:\git\parsing\.venv\lib\site-packages\validx\py\abstract.py", line 252, in _load_recurcive
    return class_(**result)
TypeError: Const.__init__() missing 1 required positional argument: 'value'

This error is caused by the params method in the Validator class in abstract.py:

    def params(self):
        for slot in self.__slots__:
            value = getattr(self, slot)
            if value is not None and value is not False:
                yield slot, value

I don't know what the procedure is for a pull request (or if you'd rather do it yourself), but checking if the class isn't an instance of Const and then allowing False as a value would probably fix it.

kr41 commented 1 year ago

checking if the class isn't an instance of Const and then allowing False as a value would probably fix it.

I'll try to find more elegant solution. However the bug itself is really cool :)

draggeta commented 1 year ago

That makes sense as this is a parent class. Thank you for the quick reply btw.