MCPcopy Create free account
hub / github.com/astral-sh/ruff / fmt

Method fmt

crates/ruff_python_parser/src/semantic_errors.rs:1392–1564  ·  view source on GitHub ↗
(&self, f: &mut std::fmt::Formatter<'_>)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 4

OkClass · 0.85
write_charMethod · 0.80
write_strMethod · 0.45
charsMethod · 0.45

Tested by

no test coverage detected