Add support for PEP 696 syntax (#11120)

This commit is contained in:
Jelle Zijlstra
2024-04-26 00:47:29 -07:00
committed by GitHub
parent 45725d3275
commit cd3e319538
49 changed files with 4338 additions and 669 deletions

View File

@@ -8,7 +8,15 @@ pub struct FormatTypeParamParamSpec;
impl FormatNodeRule<TypeParamParamSpec> for FormatTypeParamParamSpec {
fn fmt_fields(&self, item: &TypeParamParamSpec, f: &mut PyFormatter) -> FormatResult<()> {
let TypeParamParamSpec { range: _, name } = item;
write!(f, [token("**"), name.format()])
let TypeParamParamSpec {
range: _,
name,
default,
} = item;
write!(f, [token("**"), name.format()])?;
if let Some(default) = default {
write!(f, [space(), token("="), space(), default.format()])?;
}
Ok(())
}
}

View File

@@ -12,11 +12,15 @@ impl FormatNodeRule<TypeParamTypeVar> for FormatTypeParamTypeVar {
range: _,
name,
bound,
default,
} = item;
name.format().fmt(f)?;
if let Some(bound) = bound {
write!(f, [token(":"), space(), bound.format()])?;
}
if let Some(default) = default {
write!(f, [space(), token("="), space(), default.format()])?;
}
Ok(())
}
}

View File

@@ -8,7 +8,15 @@ pub struct FormatTypeParamTypeVarTuple;
impl FormatNodeRule<TypeParamTypeVarTuple> for FormatTypeParamTypeVarTuple {
fn fmt_fields(&self, item: &TypeParamTypeVarTuple, f: &mut PyFormatter) -> FormatResult<()> {
let TypeParamTypeVarTuple { range: _, name } = item;
write!(f, [token("*"), name.format()])
let TypeParamTypeVarTuple {
range: _,
name,
default,
} = item;
write!(f, [token("*"), name.format()])?;
if let Some(default) = default {
write!(f, [space(), token("="), space(), default.format()])?;
}
Ok(())
}
}