mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 01:51:30 +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)
|
||||
}
|
||||
|
||||
/// 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>> {
|
||||
match self {
|
||||
Type::Class(class_type) => Some(class_type),
|
||||
|
|
|
@ -27,7 +27,15 @@ pub struct DisplayType<'db> {
|
|||
impl Display for DisplayType<'_> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
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}]",)
|
||||
} else {
|
||||
representation.fmt(f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue