mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-19 02:55:50 +00:00
Consolidate error handling for builtin "constants" mutations
Co-authored-by: Jeong YunWon <youknowone@users.noreply.github.com>
This commit is contained in:
parent
be92bc5243
commit
e038799297
1 changed files with 6 additions and 13 deletions
|
@ -396,19 +396,12 @@ impl Compiler {
|
|||
}
|
||||
|
||||
fn check_forbidden_name(&self, name: &str, usage: NameUsage) -> CompileResult<()> {
|
||||
if usage == NameUsage::Store && is_forbidden_name(name) {
|
||||
return Err(self.error(CompileErrorType::SyntaxError(format!(
|
||||
"cannot assign to {}",
|
||||
name
|
||||
))));
|
||||
}
|
||||
if usage == NameUsage::Delete && is_forbidden_name(name) {
|
||||
return Err(self.error(CompileErrorType::SyntaxError(format!(
|
||||
"cannot delete {}",
|
||||
name
|
||||
))));
|
||||
}
|
||||
Ok(())
|
||||
let msg = match usage {
|
||||
NameUsage::Store if is_forbidden_name(name) => "cannot assign to",
|
||||
NameUsage::Delete if is_forbidden_name(name) => "cannot delete",
|
||||
_ => return Ok(()),
|
||||
};
|
||||
Err(self.error(CompileErrorType::SyntaxError(format!("{} {}", msg, name))))
|
||||
}
|
||||
|
||||
fn compile_name(&mut self, name: &str, usage: NameUsage) -> CompileResult<()> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue