audeering / audobject

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

Fix: properly serialize keyword arguments #51

Closed frankenjoe closed 2 years ago

frankenjoe commented 2 years ago

Fixes #50

Instead of serializing all attributes to YAML, we only store the attributes that are actually passed as keyword arguments. Therefore, we pass kwargs to the constructor of the base class.

image

codecov[bot] commented 2 years ago

Codecov Report

Merging #51 (adb84c3) into master (a12c77c) will not change coverage. The diff coverage is 100.0%.

Impacted Files Coverage Δ
audobject/core/define.py 100.0% <100.0%> (ø)
audobject/core/dictionary.py 100.0% <100.0%> (ø)
audobject/core/object.py 100.0% <100.0%> (ø)
audobject/core/testing.py 100.0% <100.0%> (ø)
hagenw commented 2 years ago

This implementation also introduces another way of hiding arguments as a side effect. If you use **kwargs but not pass them to super.__init__() I guess they are not stored, but handled like hidden arguments. Or will it raise an error?

frankenjoe commented 2 years ago

This implementation also introduces another way of hiding arguments as a side effect. If you use **kwargs but not pass them to super.init() I guess they are not stored, but handled like hidden arguments.

Yep, and it's actually quite handy since we often use **kwargs to capture deprecated arguments, which we don't want to serialize.

Or will it raise an error?

Nope

hagenw commented 2 years ago

This implementation also introduces another way of hiding arguments as a side effect. If you use kwargs but not pass them to super.init**() I guess they are not stored, but handled like hidden arguments.

Yep, and it's actually quite handy since we often use **kwargs to capture deprecated arguments, which we don't want to serialize.

Or will it raise an error?

Nope

Cool, can you then also add a test for it.

frankenjoe commented 2 years ago

Cool, can you then also add a test for it.

Turns out since @audeer.deprecated_keyword_argument removes the argument, we can even call super().__init__(**kwargs). I extended the test accordingly.