Skip to content

Commit

Permalink
[red-knot] Inline Type::is_literal (#13230)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood authored Sep 3, 2024
1 parent 50c8ee5 commit dfee658
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
13 changes: 0 additions & 13 deletions crates/red_knot_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
10 changes: 9 additions & 1 deletion crates/red_knot_python_semantic/src/types/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dfee658

Please sign in to comment.