@@ -951,11 +951,7 @@ impl<'db> KnownClass {
951951 /// Lookup a [`KnownClass`] in typeshed and return a [`Type`]
952952 /// representing all possible instances of the class.
953953 ///
954- /// ## Panics
955- ///
956- /// This method will panic if the class cannot be found in typeshed
957- /// and *either* the `test` feature *or* the `debug_assertions` feature is enabled.
958- /// See [`KnownClass::to_class_literal`] for more details.
954+ /// If the class cannot be found in typeshed, a debug-level log message will be emitted stating this.
959955 pub ( crate ) fn to_instance ( self , db : & ' db dyn Db ) -> Type < ' db > {
960956 self . to_class_literal ( db)
961957 . into_class_literal ( )
@@ -986,42 +982,7 @@ impl<'db> KnownClass {
986982
987983 /// Lookup a [`KnownClass`] in typeshed and return a [`Type`] representing that class-literal.
988984 ///
989- /// ## Invariants upheld by this method
990- ///
991- /// When executed outside of tests, this method should never panic: if the symbol cannot
992- /// be found in typeshed, the method simply returns [`Type::unknown()`].
993- /// When executed in the context of tests, however, this method panics rather than falling
994- /// back to `Unknown` if a symbol cannot be found.
995- ///
996- /// This means that two desirable properties are upheld:
997- /// 1. red-knot works on (nearly) arbitrary custom typesheds without panicking when run
998- /// outside of our tests. This is a potentially useful feature for a variety of reasons.
999- /// 2. Implicit behaviour is kept to a minimum in the context of our tests.
1000- /// If [`KnownClass`] symbols silently fell back to `Unknown` in the context of a test
1001- /// that used a custom typeshed directory, it might lead to hard-to-debug test failures
1002- /// and confusing behaviour.
1003- ///
1004- /// ## When this method panics
1005- ///
1006- /// This method panics if both the following conditions are met:
1007- /// 1. Either no symbol can be found for the class in typeshed,
1008- /// OR the found symbol is not a class definition,
1009- /// OR the found symbol is possibly unbound.
1010- /// 2. Either the `test` feature is enabled,
1011- /// OR the `debug_assertions` feature is enabled.
1012- ///
1013- /// If condition (1) is met but condition (2) is not, we simply log a debug warning
1014- /// and fall back to `Unknown`.
1015- ///
1016- /// ## Why do we panic if *either* `test` *or* `debug_assertions` is enabled?
1017- ///
1018- /// Some of our tests are not run in a context where the `test` feature is enabled
1019- /// (for example, mdtests). Meanwhile, other tests are never run in our CI with
1020- /// `debug_assertions` enabled, because running them with a debug build would take too
1021- /// long (our property tests). For both of these tests, however, we want to avoid
1022- /// special-cases symbols silently falling back to `Unknown`. Panicking if *either*
1023- /// `test` is enabled *or* `debug_assertions` is enabled covers both cases, while still
1024- /// avoiding panicking when red-knot is run on production code.
985+ /// If the class cannot be found in typeshed, a debug-level log message will be emitted stating this.
1025986 pub ( crate ) fn to_class_literal ( self , db : & ' db dyn Db ) -> Type < ' db > {
1026987 // a cache of the `KnownClass`es that we have already failed to lookup in typeshed
1027988 // (and therefore that we've already logged a warning for)
@@ -1030,12 +991,6 @@ impl<'db> KnownClass {
1030991 self . try_to_class_literal ( db)
1031992 . map ( Type :: ClassLiteral )
1032993 . unwrap_or_else ( |lookup_error| {
1033- assert ! (
1034- !cfg!( any( test, debug_assertions) ) ,
1035- "{}" ,
1036- lookup_error. display( db, self )
1037- ) ;
1038-
1039994 if MESSAGES . lock ( ) . unwrap ( ) . insert ( self ) {
1040995 if matches ! (
1041996 lookup_error,
@@ -1063,11 +1018,7 @@ impl<'db> KnownClass {
10631018 /// Lookup a [`KnownClass`] in typeshed and return a [`Type`]
10641019 /// representing that class and all possible subclasses of the class.
10651020 ///
1066- /// ## Panics
1067- ///
1068- /// This method will panic if the class cannot be found in typeshed
1069- /// and *either* the `test` feature *or* the `debug_assertions` feature is enabled.
1070- /// See [`KnownClass::to_class_literal`] for more details.
1021+ /// If the class cannot be found in typeshed, a debug-level log message will be emitted stating this.
10711022 pub ( crate ) fn to_subclass_of ( self , db : & ' db dyn Db ) -> Type < ' db > {
10721023 self . to_class_literal ( db)
10731024 . into_class_literal ( )
0 commit comments