[red-knot] rename {Class,Module,Function} => {Class,Module,Function}Literal (#13873)

## Summary

* Rename `Type::Class` => `Type::ClassLiteral`
* Rename `Type::Function` => `Type::FunctionLiteral`
* Do not rename `Type::Module`
* Remove `*Literal` suffixes in `display::LiteralTypeKind` variants, as
per clippy suggestion
* Get rid of `Type::is_class()` in favor of `is_subtype_of(…, 'type')`;
modifiy `is_subtype_of` to support this.
* Add new `Type::is_xyz()` methods and use them instead of matching on
`Type` variants.

closes #13863 

## Test Plan

New `is_subtype_of_class_literals` unit test.

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
David Peter 2024-10-22 22:10:53 +02:00 committed by GitHub
parent c6ce52c29e
commit f335fe4d4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 163 additions and 117 deletions

View file

@ -175,7 +175,6 @@ mod tests {
use crate::db::tests::TestDb;
use crate::program::{Program, SearchPathSettings};
use crate::python_version::PythonVersion;
use crate::types::Type;
use crate::{HasTy, ProgramSettings, SemanticModel};
fn setup_db<'a>(files: impl IntoIterator<Item = (&'a str, &'a str)>) -> anyhow::Result<TestDb> {
@ -205,7 +204,7 @@ mod tests {
let model = SemanticModel::new(&db, foo);
let ty = function.ty(&model);
assert!(matches!(ty, Type::Function(_)));
assert!(ty.is_function_literal());
Ok(())
}
@ -222,7 +221,7 @@ mod tests {
let model = SemanticModel::new(&db, foo);
let ty = class.ty(&model);
assert!(matches!(ty, Type::Class(_)));
assert!(ty.is_class_literal());
Ok(())
}
@ -243,7 +242,7 @@ mod tests {
let model = SemanticModel::new(&db, bar);
let ty = alias.ty(&model);
assert!(matches!(ty, Type::Class(_)));
assert!(ty.is_class_literal());
Ok(())
}