(&self, f: &mut std::fmt::Formatter<'_>)
| 1382 | |
| 1383 | impl Display for SemanticSyntaxError { |
| 1384 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 1385 | match &self.kind { |
| 1386 | SemanticSyntaxErrorKind::LateFutureImport => { |
| 1387 | f.write_str("__future__ imports must be at the top of the file") |
| 1388 | } |
| 1389 | SemanticSyntaxErrorKind::NamedExpressionInComprehensionIterable => f.write_str( |
| 1390 | "assignment expression cannot be used in a comprehension iterable expression", |
| 1391 | ), |
| 1392 | SemanticSyntaxErrorKind::NamedExpressionInClassBodyComprehension => f.write_str( |
| 1393 | "assignment expression within a comprehension cannot be used in a class body", |
| 1394 | ), |
| 1395 | SemanticSyntaxErrorKind::ReboundComprehensionVariable => { |
| 1396 | f.write_str("assignment expression cannot rebind comprehension variable") |
| 1397 | } |
| 1398 | SemanticSyntaxErrorKind::DuplicateTypeParameter => { |
| 1399 | f.write_str("duplicate type parameter") |
| 1400 | } |
| 1401 | SemanticSyntaxErrorKind::TypeParameterDefaultOrder(name) => { |
| 1402 | write!( |
| 1403 | f, |
| 1404 | "non default type parameter `{name}` follows default type parameter" |
| 1405 | ) |
| 1406 | } |
| 1407 | SemanticSyntaxErrorKind::MultipleCaseAssignment(name) => { |
| 1408 | write!(f, "multiple assignments to name `{name}` in pattern") |
| 1409 | } |
| 1410 | SemanticSyntaxErrorKind::MultipleStarredNamesInSequencePattern => { |
| 1411 | f.write_str("multiple starred names in sequence pattern") |
| 1412 | } |
| 1413 | SemanticSyntaxErrorKind::IrrefutableCasePattern(kind) => match kind { |
| 1414 | // These error messages are taken from CPython's syntax errors |
| 1415 | IrrefutablePatternKind::Name(name) => { |
| 1416 | write!( |
| 1417 | f, |
| 1418 | "name capture `{name}` makes remaining patterns unreachable" |
| 1419 | ) |
| 1420 | } |
| 1421 | IrrefutablePatternKind::Wildcard => { |
| 1422 | f.write_str("wildcard makes remaining patterns unreachable") |
| 1423 | } |
| 1424 | }, |
| 1425 | SemanticSyntaxErrorKind::SingleStarredAssignment => { |
| 1426 | f.write_str("starred assignment target must be in a list or tuple") |
| 1427 | } |
| 1428 | SemanticSyntaxErrorKind::WriteToDebug(kind) => match kind { |
| 1429 | WriteToDebugKind::Store => f.write_str("cannot assign to `__debug__`"), |
| 1430 | WriteToDebugKind::Delete => write!( |
| 1431 | f, |
| 1432 | "cannot delete `__debug__` on Python {} (syntax was removed in 3.9)", |
| 1433 | self.python_version, |
| 1434 | ), |
| 1435 | WriteToDebugKind::DeleteAttribute => write!( |
| 1436 | f, |
| 1437 | "cannot delete `__debug__` on Python {} (syntax was removed in 3.14)", |
| 1438 | self.python_version, |
| 1439 | ), |
| 1440 | WriteToDebugKind::AugAssignAttribute => write!( |
| 1441 | f, |
nothing calls this directly
no test coverage detected