Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP8: Avoid bare exceptions #108

Closed
wants to merge 1 commit into from
Closed

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Dec 11, 2023

PR Description

Purpose

We have a bare exception.

From PEP8:

When catching exceptions, mention specific exceptions whenever possible instead of using a bare except: clause:

try:
   import platform_specific_module
except ImportError:
   platform_specific_module = None

A bare except: clause will catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. If you want to catch all exceptions that signal program errors, use except Exception: (bare except is equivalent to except BaseException:).

Approach

How does this change address the problem?

Fix the bare exception as recommended in PEP8.

Blog Posts

@monim67
Copy link
Owner

monim67 commented Dec 11, 2023

Can you please improve the PR description? I don't understand it.

@cclauss
Copy link
Contributor Author

cclauss commented Dec 11, 2023

The title says that PEP8 encourages developers to avoid bare exceptions.
The first line of the commit body is a link to an article explains why bare exceptions are really bad
The second line is a link to the ruff lint rule which explains what bare exceptions are. The Why is this bad? explains why the proposed change is a good idea.

@cclauss cclauss closed this Mar 26, 2024
@cclauss cclauss deleted the patch-1 branch March 26, 2024 13:39
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.

2 participants