@@ -45,7 +45,7 @@ use ruff_python_ast::{self as ast, AnyNodeRef, PythonVersion, StringFlags};
4545use ruff_text_size:: { Ranged , TextRange } ;
4646use rustc_hash:: FxHashSet ;
4747use std:: fmt:: { self , Formatter } ;
48- use ty_module_resolver:: { Module , ModuleName } ;
48+ use ty_module_resolver:: { KnownModule , Module , ModuleName , file_to_module } ;
4949
5050const RUNTIME_CHECKABLE_DOCS_URL : & str =
5151 "https://docs.python.org/3/library/typing.html#typing.runtime_checkable" ;
@@ -3018,6 +3018,26 @@ pub(super) fn report_invalid_assignment<'db>(
30183018 let message = diag. primary_message ( ) . to_string ( ) ;
30193019 diag. set_concise_message ( message) ;
30203020 }
3021+
3022+ // special case message
3023+ if let Type :: NominalInstance ( target_instance) = target_ty {
3024+ let db = context. db ( ) ;
3025+ let file = target_instance. class ( db) . class_literal ( db) . file ( db) ;
3026+ if let Some ( module) = file_to_module ( db, file)
3027+ && module. is_known ( db, KnownModule :: Numbers )
3028+ {
3029+ let is_numeric = [ KnownClass :: Int , KnownClass :: Float , KnownClass :: Complex ]
3030+ . iter ( )
3031+ . any ( |numeric| value_ty. is_subtype_of ( db, numeric. to_instance ( db) ) ) ;
3032+
3033+ if is_numeric {
3034+ diag. info (
3035+ "Types from the `numbers` module aren't supported for static type checking" ,
3036+ ) ;
3037+ diag. help ( "Consider using a protocol instead, such as `typing.SupportsFloat`" ) ;
3038+ }
3039+ }
3040+ }
30213041}
30223042
30233043pub ( super ) fn report_invalid_attribute_assignment (
0 commit comments