raising-not-implemented

Try in Playground
python-best-practicesBest PracticeError

0

No tags

No CWE or CVE

Code should not raise NotImplemented and instead use NotImplementedError. NotImplemented is a value (as per the documentation, not an exception. The proper exception is NotImplementedError

Pattern Rule: raise ${exceptionName}


raising-not-implemented

How to write a rule
function visit(pattern, filename, code) {
  const exceptionName = pattern.variables.get("exceptionName");
  if (exceptionName && exceptionName.value === "NotImplemented") {
    const error = buildError(pattern.start.line, pattern.start.col, pattern.end.line, pattern.end.col, "raise NotImplemented is not a valid error", "INFO", "BEST_PRACTICES");
    const edit = buildEdit(pattern.start.line, pattern.start.col, pattern.end.line, pattern.end.col, "update", "raise NotImplementedError");
    const fix = buildFix("raise NotImplementedError", [edit]);
    addError(error.addFix(fix));
  }
}

raise-notimplemented.py

Expected test result: has error

a = 1
b = 2
raise NotImplemented
c = 3

raise-notimplementederror.py

Expected test result: no error

a = 1
b = 2
raise NotImplementedError
c = 3
Add comment

Log in to add a comment


    Be the first one to leave a comment!

Codiga Logo
Codiga Hub
  • Rulesets
  • Playground
  • Snippets
  • Cookbooks
Legal
  • Security
  • Privacy Policy
  • Code Privacy
  • Terms of Service
soc-2 icon

We are SOC-2 Compliance Certified

G2 high performer medal

Codiga – All rights reserved 2022.