audeering / audobject

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

FIX: inherit borrow, hide, and resolvers #13

Closed frankenjoe closed 3 years ago

frankenjoe commented 3 years ago

Closes https://github.com/audeering/audobject/issues/12

Example

import audobject

__version__ = '1.0.0'

class Parent(audobject.Object):
    @audobject.init_decorator(
        hide=[            
            'parent',
        ],
    )
    def __init__(
            self,
            parent: bool = False,
    ):
        self.parent = parent

class Child(Parent):
    @audobject.init_decorator(
        hide=[
            'child',            
        ],
    )
    def __init__(
            self,
            child: bool = False,
            parent: bool = False,
    ):        
        super().__init__(parent=parent)
        self.child = child

c = Child()
print(c.to_yaml_s())
$__main__.Child==1.0.0: {}
frankenjoe commented 3 years ago

I added a unit test for hide, but I locally verified that borrow and resolvers are also working.

codecov[bot] commented 3 years ago

Codecov Report

Merging #13 (50b7fba) into master (82dd562) will not change coverage. The diff coverage is 100.0%.

Impacted Files Coverage Δ
audobject/core/decorator.py 100.0% <100.0%> (ø)
hagenw commented 3 years ago

When I execute your code above I get:

/home/audeering.local/hwierstorf/git/audeering/audobject/audobject/core/object.py:292: RuntimeWarning: Could not determine a version for module '__main__'.
  RuntimeWarning,
$__main__.Child: {}

Did you just suppress the warning in your example, because it's not relevant?

hagenw commented 3 years ago

I just double checked what happens if parent shouldn't be hidden and it works as well:

class Parent(audobject.Object):
    def __init__(
            self,
            parent: bool = False,
    ):
        self.parent = parent

class Child(Parent):
    @audobject.init_decorator(
        hide=[
            'child',            
        ],
    )
    def __init__(
            self,
            child: bool = False,
            parent: bool = False,
    ):        
        super().__init__(parent=parent)
        self.child = child

c = Child()
print(c.to_yaml_s())
$__main__.Child:
  parent: false
frankenjoe commented 3 years ago

Did you just suppress the warning in your example, because it's not relevant?

you can suppress it by adding:

__version__ = '1.0.0'
frankenjoe commented 3 years ago

I just double checked what happens if parent shouldn't be hidden and it works as well:

Well, that was already working before, which is the reason we only found the bug now :)