diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2024-01-04 11:15:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-04 11:15:56 +0300 |
commit | 397251ba0cc1a1df2c558c28c416b64eef73a051 (patch) | |
tree | c5bd1c25eae4d890b7f5f79d938ca5e04802bafc /modules/extensions.py | |
parent | 149c9d223463c8fc34f53f26ca06e02be4c8835b (diff) | |
parent | df62ffbd2525792c115adefdbaeb7799699624b1 (diff) |
Merge pull request #14527 from akx/avoid-isfiles
Avoid unnecessary `isfile`/`exists` calls
Diffstat (limited to 'modules/extensions.py')
-rw-r--r-- | modules/extensions.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/modules/extensions.py b/modules/extensions.py index 1899cd52..99e7ee60 100644 --- a/modules/extensions.py +++ b/modules/extensions.py @@ -32,11 +32,12 @@ class ExtensionMetadata: self.config = configparser.ConfigParser()
filepath = os.path.join(path, self.filename)
- if os.path.isfile(filepath):
- try:
- self.config.read(filepath)
- except Exception:
- errors.report(f"Error reading {self.filename} for extension {canonical_name}.", exc_info=True)
+ # `self.config.read()` will quietly swallow OSErrors (which FileNotFoundError is),
+ # so no need to check whether the file exists beforehand.
+ try:
+ self.config.read(filepath)
+ except Exception:
+ errors.report(f"Error reading {self.filename} for extension {canonical_name}.", exc_info=True)
self.canonical_name = self.config.get("Extension", "Name", fallback=canonical_name)
self.canonical_name = canonical_name.lower().strip()
|