From 5a8c50d376be6eeed398c8e7d7eef1ba93ce8345 Mon Sep 17 00:00:00 2001 From: Emily Boudreaux Date: Sat, 22 Mar 2025 07:13:34 -0400 Subject: [PATCH] fix(opatio): fixed global numTables previously there was a global "default header" object which each OpatIO table used to build off of. The issue was that this did a shallow copy so if there were multiple OpatIO objects instantiated they would all modify the same header object. This has been resolved by moving the default header to a function which generates it fresh for each OpatIO object. --- utils/opatio/src/opatio/opat/opat.py | 31 ++++++++++++++++------------ 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/utils/opatio/src/opatio/opat/opat.py b/utils/opatio/src/opatio/opat/opat.py index 278b62a..8e3cc83 100644 --- a/utils/opatio/src/opatio/opat/opat.py +++ b/utils/opatio/src/opatio/opat/opat.py @@ -48,18 +48,23 @@ class OPATTable: logT: Iterable[float] #< Logarithm of T values logKappa: Iterable[Iterable[float]] #< Logarithm of Kappa values -defaultHeader = Header( - magic="OPAT", - version=1, - numTables=0, - headerSize=256, - indexOffset=0, - creationDate=datetime.now().strftime("%b %d, %Y"), - sourceInfo="no source provided by user", - comment="default header", - numIndex=2, - reserved=b"\x00" * 24 -) +def make_default_header() -> Header: + """ + @brief Create a default header for an OPAT file. + @return The default header. + """ + return Header( + magic="OPAT", + version=1, + numTables=0, + headerSize=256, + indexOffset=0, + creationDate=datetime.now().strftime("%b %d, %Y"), + sourceInfo="no source provided by user", + comment="default header", + numIndex=2, + reserved=b"\x00" * 24 + ) class OpatIO: """ @@ -103,7 +108,7 @@ class OpatIO: Save the OPAT file as a binary file. """ def __init__(self): - self.header: Header = defaultHeader + self.header: Header = make_default_header() self.tables: List[Tuple[Tuple[float, float], OPATTable]] = [] @staticmethod