From f2714e96e48be31f687e8765f923fd5373389592 Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Thu, 21 Dec 2023 14:34:43 -0500 Subject: [PATCH] Use model_construct in a few already-validated contexts. This was by no means a comprehensive attempt to find cases like this, just a few I happened to spot. --- python/lsst/daf/butler/datastore/cache_manager.py | 2 +- python/lsst/daf/butler/logging.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/lsst/daf/butler/datastore/cache_manager.py b/python/lsst/daf/butler/datastore/cache_manager.py index 00c9cc405d..3d4e03a76e 100644 --- a/python/lsst/daf/butler/datastore/cache_manager.py +++ b/python/lsst/daf/butler/datastore/cache_manager.py @@ -169,7 +169,7 @@ def from_file(cls, file: ResourcePath, root: ResourcePath) -> CacheEntry: id_, component, _ = _parse_cache_name(file_in_cache) stat = os.stat(file.ospath) - return cls( + return cls.model_construct( name=file_in_cache, size=stat.st_size, ref=id_, diff --git a/python/lsst/daf/butler/logging.py b/python/lsst/daf/butler/logging.py index 7cb892825c..dddf197584 100644 --- a/python/lsst/daf/butler/logging.py +++ b/python/lsst/daf/butler/logging.py @@ -300,7 +300,7 @@ def from_records(cls, records: Iterable[ButlerLogRecord]) -> "ButlerLogRecords": records : iterable of `ButlerLogRecord` The records to seed this class with. """ - return cls(root=list(records)) + return cls.model_construct(root=list(records)) @classmethod def from_file(cls, filename: str) -> "ButlerLogRecords": @@ -546,7 +546,7 @@ class ButlerLogRecordHandler(StreamHandler): def __init__(self) -> None: super().__init__() - self.records = ButlerLogRecords([]) + self.records = ButlerLogRecords.model_construct(root=[]) def emit(self, record: LogRecord) -> None: self.records.append(record)