(vm: &VirtualMachine, expr: &ast::Expr)
| 125 | } |
| 126 | |
| 127 | fn validate_pattern_match_value(vm: &VirtualMachine, expr: &ast::Expr) -> PyResult<()> { |
| 128 | validate_expr(vm, expr, ast::ExprContext::Load)?; |
| 129 | match expr { |
| 130 | ast::Expr::NumberLiteral(_) | ast::Expr::StringLiteral(_) | ast::Expr::BytesLiteral(_) => { |
| 131 | Ok(()) |
| 132 | } |
| 133 | ast::Expr::Attribute(_) => Ok(()), |
| 134 | ast::Expr::UnaryOp(op) => match &*op.operand { |
| 135 | ast::Expr::NumberLiteral(_) => Ok(()), |
| 136 | _ => Err(vm.new_value_error("patterns may only match literals and attribute lookups")), |
| 137 | }, |
| 138 | ast::Expr::BinOp(bin) => match (&*bin.left, &*bin.right) { |
| 139 | (ast::Expr::NumberLiteral(_), ast::Expr::NumberLiteral(_)) => Ok(()), |
| 140 | _ => Err(vm.new_value_error("patterns may only match literals and attribute lookups")), |
| 141 | }, |
| 142 | ast::Expr::FString(_) | ast::Expr::TString(_) => Ok(()), |
| 143 | ast::Expr::BooleanLiteral(_) |
| 144 | | ast::Expr::NoneLiteral(_) |
| 145 | | ast::Expr::EllipsisLiteral(_) => { |
| 146 | Err(vm.new_value_error("unexpected constant inside of a literal pattern")) |
| 147 | } |
| 148 | _ => Err(vm.new_value_error("patterns may only match literals and attribute lookups")), |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | fn validate_capture(vm: &VirtualMachine, name: &ast::Identifier) -> PyResult<()> { |
| 153 | if name.as_str() == "_" { |
no test coverage detected