audeering / audobject

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

Serialize functions #18

Closed frankenjoe closed 2 years ago

frankenjoe commented 2 years ago

Adds a new class FunctionResolver that allows it to serialize (lambda) functions.

image

codecov[bot] commented 2 years ago

Codecov Report

Merging #18 (c8ef10a) into master (c99f281) will not change coverage. The diff coverage is 100.0%.

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

If, I'm running the code example in an ipython shell, I get:

/home/audeering.local/hwierstorf/git/audeering/audobject/audobject/core/object.py:260: RuntimeWarning: Could not determine a version for module '__main__'.
  RuntimeWarning,

and the resulting YAML looks like this:

$__main__.MyObjectWithFunction:
  func: "def add(a, b):\n    return a + b\n"

Not sure if this is a problem, just wanted to point that out. So maybe it would make sense to disable the versioning for the user functions altogether?

frankenjoe commented 2 years ago

So maybe it would make sense to disable the versioning for the user functions altogether?

You always get the warning when you locally define a class, this is not related to using functions.

frankenjoe commented 2 years ago

To avoid it, you can try: __version__ = '1.0.0' in your shell

hagenw commented 2 years ago

Ah, ok, sorry I missed that. The problem is not that we deal with user defined functions, but that I defined the class also locally.