audeering / audobject

Generic Python interface for serializing objects to YAML
https://audeering.github.io/audobject/
Other
1 stars 0 forks source link

Fix handling of kwargs in constructor #50

Closed frankenjoe closed 2 years ago

frankenjoe commented 2 years ago

Currently, all attributes of an object are serialized if the constructor accepts **kwargs, e.g.:

class Object(audobject.Object):

    def __init__(
            self,
            **kwargs,
    ):
        self.foo = kwargs['foo']
        self.bar = 'not a kwarg'

o = Object(foo='a kwarg')
o.to_yaml_s()
$__main__.Object==1.0.0:
  foo: a kwarg
  bar: not a kwarg

But the expected behavior is:

$__main__.Object==1.0.0:
  foo: a kwarg
hagenw commented 2 years ago

Do I understand it correctly: we only store all attributes when **kwargs is given at the moment, otherwise we only store attributes provided as (keyword) arguments, correct? Or do we always store all attributes?

frankenjoe commented 2 years ago

Currently, when the constructor expects **kwargs we store all attributes. We need to change this to only store the attributes that match with a keyword argument.

hagenw commented 2 years ago

Currently, when the constructor expects **kwargs we store all attributes. We need to change this to only store the attributes that match with a keyword argument.

What about non-keyword arguments?

frankenjoe commented 2 years ago

What about non-keyword arguments?

Of course, those we store and also will in the future :)