Skip to content

Commit

Permalink
Add no-breakpoint checker
Browse files Browse the repository at this point in the history
This adds a checker for calls to ``breakpoint()``
or ``sys.breakpointhook()``.
This closes pylint-dev#3692
  • Loading branch information
DanielNoord committed Jul 29, 2021
1 parent c00b07b commit 881bf7d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -37,6 +37,10 @@ Release date: TBA

Closes #3878

* Added ``no-breakpoint``: Emitted when breakpoint() or sys.breakpointhook() calls are found

Closes #3692



What's New in Pylint 2.9.6?
Expand Down
4 changes: 4 additions & 0 deletions doc/whatsnew/2.10.rst
Expand Up @@ -16,6 +16,10 @@ New checkers

Closes #3826

* Added ``no-breakpoint``: Emitted when breakpoint() or sys.breakpointhook() calls are found

Closes #3692


Other Changes
=============
Expand Down
10 changes: 10 additions & 0 deletions pylint/checkers/stdlib.py
Expand Up @@ -55,6 +55,7 @@
SUBPROCESS_POPEN = "subprocess.Popen"
SUBPROCESS_RUN = "subprocess.run"
OPEN_MODULE = "_io"
BREAKPOINTS = ("builtins.breakpoint", "sys.breakpointhook")


DEPRECATED_MODULES = {
Expand Down Expand Up @@ -434,6 +435,12 @@ class StdlibChecker(DeprecatedMixin, BaseChecker):
"Using the system default implicitly can create problems on other operating systems. "
"See https://www.python.org/dev/peps/pep-0597/",
),
"W1515": (
"Leaving breakpoint() or sys.breakpointhook() in production code is unrecommended",
"no-breakpoint",
"Calls to breakpoint() and sys.breakpointhook() should be removed from code that "
"is not actively being debugged.",
),
}

def __init__(self, linter=None):
Expand Down Expand Up @@ -495,6 +502,7 @@ def _check_shallow_copy_environ(self, node):
"subprocess-run-check",
"deprecated-class",
"unspecified-encoding",
"no-breakpoint",
)
def visit_call(self, node):
"""Visit a Call node."""
Expand Down Expand Up @@ -531,6 +539,8 @@ def visit_call(self, node):
self._check_env_function(node, inferred)
elif name == SUBPROCESS_RUN:
self._check_for_check_kw_in_run(node)
elif name in BREAKPOINTS:
self.add_message("no-breakpoint", node=node)
self.check_deprecated_method(node, inferred)
except astroid.InferenceError:
return
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/n/no/no_breakpoint_py37.py
@@ -0,0 +1,6 @@
# pylint: disable=missing-docstring,no-init

import sys

breakpoint() # [no-breakpoint]
sys.breakpointhook() # [no-breakpoint]
2 changes: 2 additions & 0 deletions tests/functional/n/no/no_breakpoint_py37.rc
@@ -0,0 +1,2 @@
[testoptions]
min_pyver=3.7
2 changes: 2 additions & 0 deletions tests/functional/n/no/no_breakpoint_py37.txt
@@ -0,0 +1,2 @@
no-breakpoint:5:0::"Leaving breakpoint() or sys.breakpointhook() in production code is unrecommended"
no-breakpoint:6:0::"Leaving breakpoint() or sys.breakpointhook() in production code is unrecommended"

0 comments on commit 881bf7d

Please sign in to comment.