-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
292 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
breakpoint() | ||
|
||
|
||
import pdb | ||
from builtins import breakpoint | ||
from pdb import set_trace as st | ||
from celery.contrib.rdb import set_trace | ||
from celery.contrib import rdb | ||
import celery.contrib.rdb | ||
|
||
|
||
breakpoint() | ||
st() | ||
set_trace() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use rustc_hash::{FxHashMap, FxHashSet}; | ||
use rustpython_ast::{Expr, Stmt}; | ||
|
||
use crate::ast::helpers::{collect_call_paths, dealias_call_path, match_call_path}; | ||
use crate::ast::types::Range; | ||
use crate::checks::{Check, CheckKind}; | ||
use crate::flake8_debugger::types::DebuggerUsingType; | ||
|
||
const DEBUGGERS: &[(&str, &str)] = &[ | ||
("pdb", "set_trace"), | ||
("pudb", "set_trace"), | ||
("ipdb", "set_trace"), | ||
("ipdb", "sset_trace"), | ||
("IPython.terminal.embed", "InteractiveShellEmbed"), | ||
("IPython.frontend.terminal.embed", "InteractiveShellEmbed"), | ||
("celery.contrib.rdb", "set_trace"), | ||
("builtins", "breakpoint"), | ||
("", "breakpoint"), | ||
]; | ||
|
||
/// Checks for the presence of a debugger call. | ||
pub fn debugger_call( | ||
expr: &Expr, | ||
func: &Expr, | ||
from_imports: &FxHashMap<&str, FxHashSet<&str>>, | ||
import_aliases: &FxHashMap<&str, &str>, | ||
) -> Option<Check> { | ||
let call_path = dealias_call_path(collect_call_paths(func), import_aliases); | ||
if DEBUGGERS | ||
.iter() | ||
.any(|(module, member)| match_call_path(&call_path, module, member, from_imports)) | ||
{ | ||
Some(Check::new( | ||
CheckKind::Debugger(DebuggerUsingType::Call(call_path.join("."))), | ||
Range::from_located(expr), | ||
)) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
/// Checks for the presence of a debugger import. | ||
pub fn debugger_import(stmt: &Stmt, module: Option<&str>, name: &str) -> Option<Check> { | ||
if let Some(module) = module { | ||
if let Some((module_name, member)) = DEBUGGERS | ||
.iter() | ||
.find(|(module_name, member)| module_name == &module && member == &name) | ||
{ | ||
return Some(Check::new( | ||
CheckKind::Debugger(DebuggerUsingType::Import(format!("{module_name}.{member}"))), | ||
Range::from_located(stmt), | ||
)); | ||
} | ||
} else if DEBUGGERS | ||
.iter() | ||
.any(|(module_name, ..)| module_name == &name) | ||
{ | ||
return Some(Check::new( | ||
CheckKind::Debugger(DebuggerUsingType::Import(name.to_string())), | ||
Range::from_located(stmt), | ||
)); | ||
} | ||
None | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod checks; | ||
pub mod types; |
Oops, something went wrong.