Skip to content

Commit

Permalink
New changes due to rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed Oct 30, 2023
1 parent 5e65638 commit aaf65a1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
8 changes: 2 additions & 6 deletions crates/ruff_linter/src/rules/pylint/rules/bad_open_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use bitflags::bitflags;

use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::{self as ast, Constant, Expr};
use ruff_python_ast::{self as ast, Expr};
use ruff_python_semantic::SemanticModel;
use ruff_text_size::Ranged;

Expand Down Expand Up @@ -59,11 +59,7 @@ pub(crate) fn bad_open_mode(checker: &mut Checker, call: &ast::ExprCall) {
return;
};

let Expr::Constant(ast::ExprConstant {
value: Constant::Str(ast::StringConstant { value, .. }),
..
}) = mode
else {
let Some(ast::ExprStringLiteral { value, .. }) = mode.as_string_literal_expr() else {
return;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,15 @@ fn is_none(expr: &Expr) -> bool {
// Ex) `None`
// Note: `isinstance` only accepts `None` as a type when used with
// the union operator, so we need to check if we're in a union.
Expr::Constant(ast::ExprConstant { value, .. }) if in_union_context => value.is_none(),
Expr::NoneLiteral(_) if in_union_context => true,

// Ex) `type(None)`
Expr::Call(ast::ExprCall {
func, arguments, ..
}) if arguments.len() == 1 => {
if let Expr::Name(ast::ExprName { id, .. }) = func.as_ref() {
if id.as_str() == "type" {
if let Some(Expr::Constant(ast::ExprConstant { value, .. })) =
arguments.args.get(0)
{
return value.is_none();
}
return matches!(arguments.args.get(0), Some(Expr::NoneLiteral(_)));
}
}
false
Expand Down Expand Up @@ -134,8 +130,7 @@ fn generate_replacement(name: &str, generator: Generator) -> String {
let compare = ast::ExprCompare {
left: Box::new(var.into()),
ops: vec![ast::CmpOp::Is],
comparators: vec![ast::Expr::Constant(ast::ExprConstant {
value: ast::Constant::None,
comparators: vec![ast::Expr::NoneLiteral(ast::ExprNoneLiteral {
range: TextRange::default(),
})],
range: TextRange::default(),
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,11 @@ fn match_open_keywords(

/// Match open mode to see if it is supported.
fn match_open_mode(mode: &Expr) -> Option<ReadMode> {
let ast::StringConstant {
let ast::ExprStringLiteral {
value,
implicit_concatenated: false,
..
} = mode.as_constant_expr()?.value.as_str()?
} = mode.as_string_literal_expr()?
else {
return None;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn is_base_ten_number_literal(expr: &Expr, source: &str) -> bool {
Some([b'0', b'x' | b'X' | b'o' | b'O' | b'b' | b'B'])
)
}
_ => false,
Number::Complex { .. } => false,
}
} else {
false
Expand Down

0 comments on commit aaf65a1

Please sign in to comment.