asammdf
asammdf copied to clipboard
MDF.start_time property setter doesn't work properly
Python version
3.9.9 but I don't think this is a version dependent bug
Code
from asammdf.mdf import MDF
from datetime import datetime
mdf = MDF()
# This doens't call the property setter, instead it calls __setattr__
mdf.start_time = datetime.now()
# So the data is not set correctly
print(mdf._mdf.header.start_time) # shows the wrong value
# Instead, it sets this one
print(mdf._mdf.start_time) # shows the right value
# This calls the property getter, and doesn't return the set value
print(mdf.start_time) # shows the wrong value
Description
The MDF class has a start_time property and setter. However, the setter is never called if the user tries to set a value to start_time, __setattr__ is called instead. I can't find official docs but this stackoverflow post explains how attribute lookup works: https://stackoverflow.com/a/15751159.
I can see two possible solutions:
- Explicitly handle the
start_timecase in__setattr__ - Move the
start_timeproperty to the mdf implementation classes (MDF4etc.).
@BenWhetton can you check the latest dev branch?