Skip to content

Commit 6f475c3

Browse files
shahhamdihassanmeta-codesync[bot]
authored andcommitted
Add tests for the default severity of deprecated and unreachable
Summary: At the Pyre sync on 2026-10-29 the team agreed that `deprecated` and `unreachable` should default to the `hint` severity added for #5113, instead of `warn`. Editors already draw both in their own way, struck through or greyed out, so at `hint` they stay visible in the editor without a warning squiggle. This adds two tests that record today's behaviour under a `bug:` comment, so the change in the next diff shows up as a change in their expectations: - `test_deprecated_and_unreachable_severity` checks both kinds under three presets: `warn` with the default preset, silenced by `basic`, and `error` under `all`. - `test_deprecated_and_unreachable_in_lsp` checks that at their default severity both reach the editor as LSP warnings, with the strikethrough and greyed-out tags. Reviewed By: kinto0 Differential Revision: D128469592 fbshipit-source-id: 80fe8f5f7c31d191c7f6bff4b2b10f0ec2f28a16
1 parent 7576a23 commit 6f475c3

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎crates/pyrefly_config/src/base.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,4 +773,20 @@ mod tests {
773773
}
774774
}
775775
}
776+
777+
// https://github.com/facebook/pyrefly/issues/5113
778+
// bug: `deprecated` and `unreachable` default to `warn`; the team agreed on
779+
// 2026-10-29 that they should default to `hint`.
780+
#[test]
781+
fn test_deprecated_and_unreachable_severity() {
782+
let severity = |preset: Preset, kind| match preset.apply().errors {
783+
Some(errors) => errors.severity(kind),
784+
None => kind.default_severity(),
785+
};
786+
for kind in [ErrorKind::Deprecated, ErrorKind::Unreachable] {
787+
assert_eq!(severity(Preset::Default, kind), Severity::Warn);
788+
assert_eq!(severity(Preset::Basic, kind), Severity::Ignore);
789+
assert_eq!(severity(Preset::All, kind), Severity::Error);
790+
}
791+
}
776792
}

‎pyrefly/lib/error/error.rs‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,4 +1121,32 @@ def f(x: None) -> None:
11211121
assert_eq!(assignment.severity, Some(DiagnosticSeverity::Information));
11221122
assert_eq!(assignment.tags, None);
11231123
}
1124+
1125+
// https://github.com/facebook/pyrefly/issues/5113
1126+
// bug: at their default severity, `deprecated` and `unreachable` are LSP
1127+
// warnings; the team agreed on 2026-10-29 that they should be hints.
1128+
#[test]
1129+
fn test_deprecated_and_unreachable_in_lsp() {
1130+
let module_info = Module::new(
1131+
ModuleName::from_str("test"),
1132+
ModulePath::filesystem(PathBuf::from("test.py")),
1133+
Arc::new("x".to_owned()),
1134+
);
1135+
let diagnostic = |kind| {
1136+
Error::new(
1137+
module_info.clone(),
1138+
TextRange::new(TextSize::new(0), TextSize::new(1)),
1139+
"message".to_owned(),
1140+
Vec::new(),
1141+
kind,
1142+
)
1143+
.to_diagnostic()
1144+
};
1145+
let deprecated = diagnostic(ErrorKind::Deprecated);
1146+
assert_eq!(deprecated.severity, Some(DiagnosticSeverity::Warning));
1147+
assert_eq!(deprecated.tags, Some(vec![DiagnosticTag::Deprecated]));
1148+
let unreachable = diagnostic(ErrorKind::Unreachable);
1149+
assert_eq!(unreachable.severity, Some(DiagnosticSeverity::Warning));
1150+
assert_eq!(unreachable.tags, Some(vec![DiagnosticTag::Unnecessary]));
1151+
}
11241152
}

0 commit comments

Comments
 (0)