bare except swallows errors, including KeyboardInterrupt and SystemExit
except:
passCatch the specific exception you can handle, or let it propagate. A bare except also catches KeyboardInterrupt and SystemExit.
bare except swallows errors, including KeyboardInterrupt and SystemExit
except:
passCatch the specific exception you can handle, or let it propagate. A bare except also catches KeyboardInterrupt and SystemExit.
broad except swallows the error
except Exception:
return NoneHandle the specific error, or re-raise. Returning None here hides a real failure.
except handler returns dummy value {}
return {}Return a real result or raise. An empty dict, list, or string from except is made-up data.
except handler returns an error payload instead of raising
return "Error: failed to fetch title"Raise, or return a value the caller expects on purpose. An error string drops the traceback.
leftover debug print
print("DEBUG reached task fetch")Remove the debug call. A normal print of a finished message is left alone.
leftover debug f-string
print(f"{tasks=}")Remove the debug call. A normal print of a finished message is left alone.
leftover breakpoint or set_trace()
breakpoint()Remove the debug call. A normal print of a finished message is left alone.
try/except nested to depth 3 (limit 2)
try:
return url.strip()
except ConnectionError as exc:Flatten the handlers or split the function. Deeply nested try blocks hide which error is which.
import `requets` does not resolve
import requetsPoint the import at a real module. Optional imports belong in `try/except ImportError`. Allow known extras under rules.SLP010.allowed_modules.
import `jason` does not resolve
from jason import loadsPoint the import at a real module. Optional imports belong in `try/except ImportError`. Allow known extras under rules.SLP010.allowed_modules.
`defaultdictx` is not an attribute of `collections`
from collections import defaultdictxPoint the import at a real module. Optional imports belong in `try/except ImportError`. Allow known extras under rules.SLP010.allowed_modules.
narrating comment restates the code
# increment index
index += 1Delete the comment. Keep a comment only when it says something the code cannot.
narrating comment restates the code
# This function returns the count
def task_count(tasks):Delete the comment. Keep a comment only when it says something the code cannot.
docstring is 11 lines on a 1-statement function
def task_count(tasks):
"""Return the number of tasks.
Cut the docstring to one line, or delete it. The body is already shorter than the preface.
private function `_format_legacy_banner` is never used
def _format_legacy_banner(text):
return "*** " + text + " ***"Delete the helper, or call it. Methods are skipped; other modules may use them.
over-defensive check: `name` is a non-None literal here
if name is not None:
return name.upper()Delete the branch. Checks on parameters and on values returned from calls are kept.
function body is only pass
def export_tasks(tasks, path):
"""Write tasks somewhere eventually."""
passImplement the function or delete it. Abstract methods and `.pyi` stubs are ignored.
commented-out code (2 lines)
# status = "archived"
# owner = "ada"Delete it. Version control remembers the old line.
duplicate of `summarize_tasks` (100% similar)
def summarize_tasks_v2(tasks, limit):
rows = []
index = 0Keep one function and parameterize the difference. Delete the copy.
`summarize_tasks_v2` looks like a leftover versioned name
def summarize_tasks_v2(tasks, limit):
rows = []
index = 0Rename it to the real name and delete the previous copy. Suffixes like `_new` are flagged when the base name still exists.