Skip to content

fix: replace bare except with except Exception in shared.py#1163

Open
harshadkhetpal wants to merge 1 commit into
dmMaze:devfrom
harshadkhetpal:fix/bare-except-shared
Open

fix: replace bare except with except Exception in shared.py#1163
harshadkhetpal wants to merge 1 commit into
dmMaze:devfrom
harshadkhetpal:fix/bare-except-shared

Conversation

@harshadkhetpal
Copy link
Copy Markdown

Summary

Replace bare except: with except Exception: in utils/shared.py.

PEP 8 recommends against bare except: — it should specify an exception type. Since this catch block handles an error without re-raising (prints and falls back to empty dict), except Exception: is the correct replacement.

Change:

# Before
try:
    with open(cache_path, "r", encoding="utf8") as file:
        cache_data = json.load(file)
except:
    print(f'cached file {cache_path} is invalid')
    cache_data = {}

# After
except Exception:
    print(f'cached file {cache_path} is invalid')
    cache_data = {}

Testing

No behavior change — style/correctness fix only. Using except Exception: avoids catching SystemExit, KeyboardInterrupt, etc.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant