Skip to content

Instantly share code, notes, and snippets.

@weishi-imbue
Created April 17, 2026 23:47
Show Gist options
  • Select an option

  • Save weishi-imbue/2719d1efedf8b4c22628ad3213111397 to your computer and use it in GitHub Desktop.

Select an option

Save weishi-imbue/2719d1efedf8b4c22628ad3213111397 to your computer and use it in GitHub Desktop.
def _initialize_info(self) -> None:
"""Import module and set `self.installed` and `self.version`."""
self._version = None
try:
module = importlib.import_module(self.name)
except (ImportError, ValueError):
self._installed = False
return
else:
self._installed = True
+ finally:
+ self._initialized = True
for attribute_name in self._version_attributes:
if hasattr(module, attribute_name):
version = getattr(module, attribute_name)
assert isinstance(version, (str, float))
self._version = str(version)
break
def get_version(self) -> Optional[str]:
"""Finds the module version if it exists."""
if not self._initialized:
self._initialize_info()
return self._version
@weishi-imbue

Copy link
Copy Markdown
Author

self._initialized was being read but never updated in the ModuleInfo class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment