mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 18:11:08 +00:00
[red-knot] Inline Type::is_literal
(#13230)
This commit is contained in:
parent
50c8ee5175
commit
dfee65882b
2 changed files with 9 additions and 14 deletions
|
@ -220,19 +220,6 @@ impl<'db> Type<'db> {
|
||||||
matches!(self, Type::Never)
|
matches!(self, Type::Never)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this type should be displayed as a literal value.
|
|
||||||
pub const fn is_literal(&self) -> bool {
|
|
||||||
matches!(
|
|
||||||
self,
|
|
||||||
Type::IntLiteral(_)
|
|
||||||
| Type::BooleanLiteral(_)
|
|
||||||
| Type::StringLiteral(_)
|
|
||||||
| Type::BytesLiteral(_)
|
|
||||||
| Type::Class(_)
|
|
||||||
| Type::Function(_)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub const fn into_class_type(self) -> Option<ClassType<'db>> {
|
pub const fn into_class_type(self) -> Option<ClassType<'db>> {
|
||||||
match self {
|
match self {
|
||||||
Type::Class(class_type) => Some(class_type),
|
Type::Class(class_type) => Some(class_type),
|
||||||
|
|
|
@ -27,7 +27,15 @@ pub struct DisplayType<'db> {
|
||||||
impl Display for DisplayType<'_> {
|
impl Display for DisplayType<'_> {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
let representation = self.ty.representation(self.db);
|
let representation = self.ty.representation(self.db);
|
||||||
if self.ty.is_literal() {
|
if matches!(
|
||||||
|
self.ty,
|
||||||
|
Type::IntLiteral(_)
|
||||||
|
| Type::BooleanLiteral(_)
|
||||||
|
| Type::StringLiteral(_)
|
||||||
|
| Type::BytesLiteral(_)
|
||||||
|
| Type::Class(_)
|
||||||
|
| Type::Function(_)
|
||||||
|
) {
|
||||||
write!(f, "Literal[{representation}]",)
|
write!(f, "Literal[{representation}]",)
|
||||||
} else {
|
} else {
|
||||||
representation.fmt(f)
|
representation.fmt(f)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue