mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
@@ -135,10 +135,12 @@ pub fn from_hex(s: &str) -> Option<f64> {
|
||||
}
|
||||
|
||||
for (index, ch) in value.chars().enumerate() {
|
||||
if ch == 'p' && has_dot {
|
||||
hex.push_str("p");
|
||||
} else if ch == 'p' && !has_dot {
|
||||
hex.push_str(".p");
|
||||
if ch == 'p' {
|
||||
if has_dot {
|
||||
hex.push('p');
|
||||
} else {
|
||||
hex.push_str(".p");
|
||||
}
|
||||
} else if index >= start {
|
||||
hex.push(ch);
|
||||
}
|
||||
|
||||
@@ -61,10 +61,7 @@ enum FunctionContext {
|
||||
|
||||
impl CompileContext {
|
||||
fn in_func(self) -> bool {
|
||||
match self.func {
|
||||
FunctionContext::NoFunction => false,
|
||||
_ => true,
|
||||
}
|
||||
!matches!(self.func, FunctionContext::NoFunction)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2006,13 +2003,9 @@ impl<O: OutputStream> Compiler<O> {
|
||||
// a list of expressions on the stack, or a list of tuples.
|
||||
fn gather_elements(&mut self, elements: &[ast::Expression]) -> CompileResult<bool> {
|
||||
// First determine if we have starred elements:
|
||||
let has_stars = elements.iter().any(|e| {
|
||||
if let ast::ExpressionType::Starred { .. } = &e.node {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
});
|
||||
let has_stars = elements
|
||||
.iter()
|
||||
.any(|e| matches!(e.node, ast::ExpressionType::Starred { .. }));
|
||||
|
||||
for element in elements {
|
||||
if let ast::ExpressionType::Starred { value } = &element.node {
|
||||
|
||||
@@ -136,19 +136,11 @@ impl Symbol {
|
||||
}
|
||||
|
||||
pub fn is_global(&self) -> bool {
|
||||
if let SymbolScope::Global = self.scope {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
matches!(self.scope, SymbolScope::Global)
|
||||
}
|
||||
|
||||
pub fn is_local(&self) -> bool {
|
||||
if let SymbolScope::Local = self.scope {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
matches!(self.scope, SymbolScope::Local)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -79,9 +79,5 @@ pub fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ast::ArgumentList,
|
||||
}
|
||||
|
||||
fn is_starred(exp: &ast::Expression) -> bool {
|
||||
if let ast::ExpressionType::Starred { .. } = exp.node {
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
matches!(exp.node, ast::ExpressionType::Starred { .. })
|
||||
}
|
||||
|
||||
@@ -393,23 +393,11 @@ where
|
||||
/// Test if a digit is of a certain radix.
|
||||
fn is_digit_of_radix(c: Option<char>, radix: u32) -> bool {
|
||||
match radix {
|
||||
2 => match c {
|
||||
Some('0'..='1') => true,
|
||||
_ => false,
|
||||
},
|
||||
8 => match c {
|
||||
Some('0'..='7') => true,
|
||||
_ => false,
|
||||
},
|
||||
10 => match c {
|
||||
Some('0'..='9') => true,
|
||||
_ => false,
|
||||
},
|
||||
16 => match c {
|
||||
Some('0'..='9') | Some('a'..='f') | Some('A'..='F') => true,
|
||||
_ => false,
|
||||
},
|
||||
x => unimplemented!("Radix not implemented: {}", x),
|
||||
2 => matches!(c, Some('0'..='1')),
|
||||
8 => matches!(c, Some('0'..='7')),
|
||||
10 => matches!(c, Some('0'..='9')),
|
||||
16 => matches!(c, Some('0'..='9') | Some('a'..='f') | Some('A'..='F')),
|
||||
other => unimplemented!("Radix not implemented: {}", other),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,10 +405,7 @@ where
|
||||
fn at_exponent(&self) -> bool {
|
||||
match self.chr0 {
|
||||
Some('e') | Some('E') => match self.chr1 {
|
||||
Some('+') | Some('-') => match self.chr2 {
|
||||
Some('0'..='9') => true,
|
||||
_ => false,
|
||||
},
|
||||
Some('+') | Some('-') => matches!(self.chr2, Some('0'..='9')),
|
||||
Some('0'..='9') => true,
|
||||
_ => false,
|
||||
},
|
||||
|
||||
@@ -77,7 +77,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
|
||||
} else {
|
||||
full_input.push_str(&line);
|
||||
}
|
||||
full_input.push_str("\n");
|
||||
full_input.push('\n');
|
||||
|
||||
if continuing {
|
||||
if stop_continuing {
|
||||
|
||||
@@ -78,7 +78,7 @@ impl StartsEndsWithArgs {
|
||||
}
|
||||
}
|
||||
|
||||
fn cap_to_isize(py_int: PyIntRef) -> isize {
|
||||
fn saturate_to_isize(py_int: PyIntRef) -> isize {
|
||||
let big = py_int.borrow_value();
|
||||
big.to_isize().unwrap_or_else(|| {
|
||||
if big.is_negative() {
|
||||
@@ -95,8 +95,8 @@ pub fn adjust_indices(
|
||||
end: Option<PyIntRef>,
|
||||
len: usize,
|
||||
) -> std::ops::Range<usize> {
|
||||
let mut start = start.map_or(0, cap_to_isize);
|
||||
let mut end = end.map_or(len as isize, cap_to_isize);
|
||||
let mut start = start.map_or(0, saturate_to_isize);
|
||||
let mut end = end.map_or(len as isize, saturate_to_isize);
|
||||
if end > len as isize {
|
||||
end = len as isize;
|
||||
} else if end < 0 {
|
||||
|
||||
@@ -378,10 +378,7 @@ enum CFormatPart {
|
||||
|
||||
impl CFormatPart {
|
||||
fn is_specifier(&self) -> bool {
|
||||
match self {
|
||||
CFormatPart::Spec(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self, CFormatPart::Spec(_))
|
||||
}
|
||||
|
||||
fn has_key(&self) -> bool {
|
||||
|
||||
@@ -146,7 +146,7 @@ impl PySlice {
|
||||
|
||||
// Each end of the array
|
||||
let lower = if backwards {
|
||||
-1_i8.to_bigint().unwrap()
|
||||
(-1_i8).to_bigint().unwrap()
|
||||
} else {
|
||||
Zero::zero()
|
||||
};
|
||||
|
||||
@@ -226,10 +226,7 @@ mod decl {
|
||||
|
||||
#[pymethod(name = "is_nonlocal")]
|
||||
fn is_nonlocal(&self) -> bool {
|
||||
match self.symbol.scope {
|
||||
symboltable::SymbolScope::Nonlocal => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(self.symbol.scope, symboltable::SymbolScope::Nonlocal)
|
||||
}
|
||||
|
||||
#[pymethod(name = "is_referenced")]
|
||||
|
||||
Reference in New Issue
Block a user