mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Apply let-else statements
This commit is contained in:
1 parent
1a92399349
commit
499b34cee0
8 files changed
+12
-31
No files matched your search
@@ -1412,9 +1412,7 @@ impl Compiler {
|
||||
) -> CompileResult<()> {
|
||||
let with_location = self.current_source_location;
|
||||
|
||||
let (item, items) = if let Some(parts) = items.split_first() {
|
||||
parts
|
||||
} else {
|
||||
let Some((item, items)) = items.split_first() else {
|
||||
return Err(self.error(CodegenErrorType::EmptyWithItems));
|
||||
};
|
||||
|
||||
|
||||
@@ -17,9 +17,7 @@ fn main() -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
fn requires_lalrpop(source: &str, target: &str) -> Option<String> {
|
||||
let target = if let Ok(target) = File::open(target) {
|
||||
target
|
||||
} else {
|
||||
let Ok(target) = File::open(target) else {
|
||||
return Some("python.rs doesn't exist. regenerate.".to_owned());
|
||||
};
|
||||
|
||||
@@ -71,9 +69,7 @@ fn requires_lalrpop(source: &str, target: &str) -> Option<String> {
|
||||
}
|
||||
|
||||
fn try_lalrpop(source: &str, target: &str) -> anyhow::Result<()> {
|
||||
let _message = if let Some(msg) = requires_lalrpop(source, target) {
|
||||
msg
|
||||
} else {
|
||||
let Some(_message) = requires_lalrpop(source, target) else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
|
||||
@@ -33,9 +33,7 @@ mod _scproxy {
|
||||
|
||||
#[pyfunction]
|
||||
fn _get_proxy_settings(vm: &VirtualMachine) -> PyResult<Option<PyDictRef>> {
|
||||
let proxy_dict = if let Some(p) = proxy_dict() {
|
||||
p
|
||||
} else {
|
||||
let Some(proxy_dict) = proxy_dict() else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
@@ -73,9 +71,7 @@ mod _scproxy {
|
||||
|
||||
#[pyfunction]
|
||||
fn _get_proxies(vm: &VirtualMachine) -> PyResult<Option<PyDictRef>> {
|
||||
let proxy_dict = if let Some(p) = proxy_dict() {
|
||||
p
|
||||
} else {
|
||||
let Some(proxy_dict) = proxy_dict() else {
|
||||
return Ok(None);
|
||||
};
|
||||
|
||||
|
||||
@@ -392,13 +392,12 @@ impl PyFunction {
|
||||
fn set_qualname(&self, value: PySetterValue, vm: &VirtualMachine) -> PyResult<()> {
|
||||
match value {
|
||||
PySetterValue::Assign(value) => {
|
||||
if let Ok(qualname) = value.downcast::<PyStr>() {
|
||||
*self.qualname.lock() = qualname;
|
||||
} else {
|
||||
let Ok(qualname) = value.downcast::<PyStr>() else {
|
||||
return Err(vm.new_type_error(
|
||||
"__qualname__ must be set to a string object".to_string(),
|
||||
));
|
||||
}
|
||||
};
|
||||
*self.qualname.lock() = qualname;
|
||||
}
|
||||
PySetterValue::Delete => {
|
||||
return Err(
|
||||
|
||||
@@ -959,9 +959,7 @@ impl GetAttr for PyType {
|
||||
))
|
||||
}
|
||||
|
||||
let name = if let Some(name) = vm.ctx.interned_str(&*name_str) {
|
||||
name
|
||||
} else {
|
||||
let Some(name) = vm.ctx.interned_str(&*name_str) else {
|
||||
return Err(attribute_error(zelf, name_str.as_str(), vm));
|
||||
};
|
||||
vm_trace!("type.__getattribute__({:?}, {:?})", zelf, name);
|
||||
|
||||
@@ -586,9 +586,7 @@ impl<T: Clone> Dict<T> {
|
||||
pred: impl Fn(&T) -> Result<bool, E>,
|
||||
) -> Result<PopInnerResult<T>, E> {
|
||||
let (entry_index, index_index) = lookup;
|
||||
let entry_index = if let Some(entry_index) = entry_index.index() {
|
||||
entry_index
|
||||
} else {
|
||||
let Some(entry_index) = entry_index.index() else {
|
||||
return Ok(ControlFlow::Break(None));
|
||||
};
|
||||
let inner = &mut *self.write();
|
||||
|
||||
@@ -243,9 +243,7 @@ impl PyNumber<'_> {
|
||||
|
||||
// PyNumber_Check
|
||||
pub fn check(obj: &PyObject) -> bool {
|
||||
let methods = if let Some(m) = Self::find_methods(obj) {
|
||||
m
|
||||
} else {
|
||||
let Some(methods) = Self::find_methods(obj) else {
|
||||
return false;
|
||||
};
|
||||
let methods = methods.as_ref();
|
||||
|
||||
@@ -110,9 +110,7 @@ mod decl {
|
||||
impl IterNextIterable for PyItertoolsChain {}
|
||||
impl IterNext for PyItertoolsChain {
|
||||
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
|
||||
let source = if let Some(source) = zelf.source.read().clone() {
|
||||
source
|
||||
} else {
|
||||
let Some(source) = zelf.source.read().clone() else {
|
||||
return Ok(PyIterReturn::StopIteration(None));
|
||||
};
|
||||
let next = loop {
|
||||
|
||||
Reference in new issue
Block a user