Created
April 17, 2026 23:47
-
-
Save weishi-imbue/2719d1efedf8b4c22628ad3213111397 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
self._initializedwas being read but never updated in the ModuleInfo class.