mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-22 20:45:11 +00:00
Add support for PEP 696 syntax (#11120)
This commit is contained in:
parent
45725d3275
commit
cd3e319538
49 changed files with 4338 additions and 669 deletions
|
@ -756,20 +756,37 @@ impl<'a> Generator<'a> {
|
|||
|
||||
pub(crate) fn unparse_type_param(&mut self, ast: &TypeParam) {
|
||||
match ast {
|
||||
TypeParam::TypeVar(TypeParamTypeVar { name, bound, .. }) => {
|
||||
TypeParam::TypeVar(TypeParamTypeVar {
|
||||
name,
|
||||
bound,
|
||||
default,
|
||||
..
|
||||
}) => {
|
||||
self.p_id(name);
|
||||
if let Some(expr) = bound {
|
||||
self.p(": ");
|
||||
self.unparse_expr(expr, precedence::MAX);
|
||||
}
|
||||
if let Some(expr) = default {
|
||||
self.p(" = ");
|
||||
self.unparse_expr(expr, precedence::MAX);
|
||||
}
|
||||
}
|
||||
TypeParam::TypeVarTuple(TypeParamTypeVarTuple { name, .. }) => {
|
||||
TypeParam::TypeVarTuple(TypeParamTypeVarTuple { name, default, .. }) => {
|
||||
self.p("*");
|
||||
self.p_id(name);
|
||||
if let Some(expr) = default {
|
||||
self.p(" = ");
|
||||
self.unparse_expr(expr, precedence::MAX);
|
||||
}
|
||||
}
|
||||
TypeParam::ParamSpec(TypeParamParamSpec { name, .. }) => {
|
||||
TypeParam::ParamSpec(TypeParamParamSpec { name, default, .. }) => {
|
||||
self.p("**");
|
||||
self.p_id(name);
|
||||
if let Some(expr) = default {
|
||||
self.p(" = ");
|
||||
self.unparse_expr(expr, precedence::MAX);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1676,6 +1693,10 @@ class Foo:
|
|||
assert_round_trip!(r"type Foo[T] = list[T]");
|
||||
assert_round_trip!(r"type Foo[*Ts] = ...");
|
||||
assert_round_trip!(r"type Foo[**P] = ...");
|
||||
assert_round_trip!(r"type Foo[T = int] = list[T]");
|
||||
assert_round_trip!(r"type Foo[*Ts = int] = ...");
|
||||
assert_round_trip!(r"type Foo[*Ts = *int] = ...");
|
||||
assert_round_trip!(r"type Foo[**P = int] = ...");
|
||||
assert_round_trip!(r"type Foo[T, U, *Ts, **P] = ...");
|
||||
// https://github.com/astral-sh/ruff/issues/6498
|
||||
assert_round_trip!(r"f(a=1, *args, **kwargs)");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue