From 64db7165593175cb1f8e5220e7d331d5053ce006 Mon Sep 17 00:00:00 2001 From: Tim Jenness Date: Wed, 24 Jul 2024 14:40:13 -0700 Subject: [PATCH] Allow for a storage class converter to be a builtin type --- python/lsst/daf/butler/_storage_class.py | 29 +++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/python/lsst/daf/butler/_storage_class.py b/python/lsst/daf/butler/_storage_class.py index 390ffbecdc..247ec77b5f 100644 --- a/python/lsst/daf/butler/_storage_class.py +++ b/python/lsst/daf/butler/_storage_class.py @@ -204,19 +204,22 @@ def _get_converters_by_type(self) -> Mapping[type, Callable[[Any], Any]]: del self._converters[candidate_type_str] continue - try: - converter = doImportType(converter_str) - except ImportError as e: - log.warning( - "Unable to import conversion function %s associated with storage class %s " - "required to convert type %s (%s)", - converter_str, - self.name, - candidate_type_str, - e, - ) - del self._converters[candidate_type_str] - continue + if hasattr(builtins, converter_str): + converter = getattr(builtins, converter_str) + else: + try: + converter = doImportType(converter_str) + except ImportError as e: + log.warning( + "Unable to import conversion function %s associated with storage class %s " + "required to convert type %s (%s)", + converter_str, + self.name, + candidate_type_str, + e, + ) + del self._converters[candidate_type_str] + continue if not callable(converter): # doImportType is annotated to return a Type but in actual # fact it can return Any except ModuleType because package