Skip to content

Commit

Permalink
Per review
Browse files Browse the repository at this point in the history
  • Loading branch information
InSyncWithFoo committed Jan 3, 2025
1 parent 580f2a2 commit 08fd1a5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import reveal_type

# `assert_type`

## Basic
Expand Down
27 changes: 26 additions & 1 deletion crates/red_knot_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,29 @@ impl<'db> Type<'db> {

/// Returns true if this type and `other` are "exactly the same".
///
/// Two types are "exactly the same" when:
///
/// * Both are either `Any` or `Unknown`, or
/// * If they are not tuples, generics, unions or intersections:
/// * They share the same internal representation.
/// * If they are tuples:
/// * They have the same length, and
/// * Each element pair are "exactly the same".
/// * If they are generics:
/// * The "origins" are "exactly the same".
/// * The argument types are "exactly the same" when compared as tuples.
/// * If they are unions:
/// * They have the same length, and
/// * For each element of the first type,
/// there exist one element of the second
/// such that they are "exactly the same";
/// each element must not be paired more than once.
/// * If they are intersections:
/// * The positive parts are "exactly the same" when compared as unions.
/// * The negative parts are "exactly the same" when compared as unions.
///
/// Note: `Todo != Todo`.
///
/// This powers the `assert_type()` directive.
pub(crate) fn is_equals_to(self, db: &'db dyn Db, other: Type<'db>) -> bool {
let equal = |(first, second): (&Type<'db>, &Type<'db>)| first.is_equals_to(db, *second);
Expand Down Expand Up @@ -3194,7 +3217,9 @@ impl KnownFunction {
pub fn constraint_function(self) -> Option<KnownConstraintFunction> {
match self {
Self::ConstraintFunction(f) => Some(f),
Self::RevealType | Self::Len | Self::Final | Self::NoTypeCheck | Self::AssertType => None,
Self::RevealType | Self::Len | Self::Final | Self::NoTypeCheck | Self::AssertType => {
None
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot_python_semantic/src/types/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ declare_lint! {
pub(crate) static TYPE_ASSERTION_FAILURE = {
summary: "detects failed type assertions",
status: LintStatus::preview("1.0.0"),
default_level: Level::Warn,
default_level: Level::Error,
}
}

Expand Down

0 comments on commit 08fd1a5

Please sign in to comment.