Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions crates/pyrefly_types/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,34 @@ pub mod tests {
);
}

n #[test]
fn test_display_param_spec() {
let tparams = fake_tparams(vec![
fake_tparam(0, "T", QuantifiedKind::TypeVar),
fake_tparam(1, "P", QuantifiedKind::ParamSpec),
fake_tparam(2, "R", QuantifiedKind::TypeVar),
]);
let method = fake_generic_bound_method(
"foo",
"MyClass",
"my.module",
tparams,
);
let mut ctx = TypeDisplayContext::new(&[&method]);
assert_eq!(
ctx.display(&method).to_string(),
"[T, **P, R](self: Any, x: Any, y: Any) -> None"
);
ctx.set_lsp_display_mode(LspDisplayMode::Hover);
assert_eq!(
ctx.display(&method).to_string(),
r#"def foo[T, **P, R](
self: Any,
x: Any,
y: Any
) -> None: ..."#
);
}
#[test]
fn test_display_overload() {
let class = fake_class("TestClass", "test", 0);
Expand Down
3 changes: 3 additions & 0 deletions crates/pyrefly_types/src/quantified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ impl Quantified {
/// in the format used for type parameter lists (e.g. `T: int = str`).
pub fn display_with_bounds(&self) -> impl Display + '_ {
Fmt(move |f| {
if self.is_param_spec() {
write!(f, "**")?;
}
write!(f, "{}", self.name)?;
match self.restriction() {
Restriction::Bound(t) => write!(f, ": {}", t)?,
Expand Down
Loading