django-bootstrap-datepicker-plus icon indicating copy to clipboard operation
django-bootstrap-datepicker-plus copied to clipboard

PEP8: Avoid bare exceptions

Open cclauss opened this issue 1 year ago • 2 comments

  • https://realpython.com/the-most-diabolical-python-antipattern
  • https://docs.astral.sh/ruff/rules/bare-except

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

cclauss avatar Dec 11 '23 08:12 cclauss

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

monim67 avatar Dec 11 '23 09:12 monim67

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 avatar Dec 11 '23 09:12 cclauss