@@ -24,9 +24,9 @@ use crate::types::signatures::{CallableSignature, Parameter, Parameters, Signatu
2424use crate :: types:: tuple:: TupleSpec ;
2525use crate :: types:: visitor:: TypeVisitor ;
2626use crate :: types:: {
27- BoundTypeVarIdentity , CallableType , IntersectionType , KnownBoundMethodType , KnownClass ,
28- MaterializationKind , Protocol , ProtocolInstanceType , StringLiteralType , SubclassOfInner , Type ,
29- UnionType , WrapperDescriptorKind , visitor,
27+ BoundTypeVarIdentity , CallableType , DynamicType , IntersectionType , KnownBoundMethodType ,
28+ KnownClass , MaterializationKind , Protocol , ProtocolInstanceType , SpecialFormType ,
29+ StringLiteralType , SubclassOfInner , Type , UnionType , WrapperDescriptorKind , visitor,
3030} ;
3131use ruff_db:: parsed:: parsed_module;
3232
@@ -470,7 +470,11 @@ impl<'db> FmtDetailed<'db> for DisplayType<'db> {
470470 | Type :: StringLiteral ( _)
471471 | Type :: BytesLiteral ( _)
472472 | Type :: EnumLiteral ( _) => {
473- f. write_str ( "Literal[" ) ?;
473+ f. with_detail ( TypeDetail :: Type ( Type :: SpecialForm (
474+ SpecialFormType :: Literal ,
475+ ) ) )
476+ . write_str ( "Literal" ) ?;
477+ f. write_char ( '[' ) ?;
474478 representation. fmt_detailed ( f) ?;
475479 f. write_str ( "]" )
476480 }
@@ -608,7 +612,16 @@ impl Display for DisplayRepresentation<'_> {
608612impl < ' db > FmtDetailed < ' db > for DisplayRepresentation < ' db > {
609613 fn fmt_detailed ( & self , f : & mut TypeWriter < ' _ , ' _ , ' db > ) -> fmt:: Result {
610614 match self . ty {
611- Type :: Dynamic ( dynamic) => write ! ( f, "{dynamic}" ) ,
615+ Type :: Dynamic ( dynamic) => {
616+ if let DynamicType :: Any = dynamic {
617+ write ! (
618+ f. with_detail( TypeDetail :: Type ( Type :: SpecialForm ( SpecialFormType :: Any ) ) ) ,
619+ "{dynamic}"
620+ )
621+ } else {
622+ write ! ( f, "{dynamic}" )
623+ }
624+ }
612625 Type :: Never => f. with_detail ( TypeDetail :: Type ( self . ty ) ) . write_str ( "Never" ) ,
613626 Type :: NominalInstance ( instance) => {
614627 let class = instance. class ( self . db ) ;
@@ -638,7 +651,12 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
638651 . fmt_detailed ( f) ,
639652 } ,
640653 Protocol :: Synthesized ( synthetic) => {
641- f. write_str ( "<Protocol with members " ) ?;
654+ f. write_char ( '<' ) ?;
655+ f. with_detail ( TypeDetail :: Type ( Type :: SpecialForm (
656+ SpecialFormType :: Protocol ,
657+ ) ) )
658+ . write_str ( "Protocol" ) ?;
659+ f. write_str ( " with members " ) ?;
642660 let interface = synthetic. interface ( ) ;
643661 let member_list = interface. members ( self . db ) ;
644662 let num_members = member_list. len ( ) ;
@@ -687,8 +705,14 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
687705 }
688706 SubclassOfInner :: Dynamic ( dynamic) => write ! ( f, "type[{dynamic}]" ) ,
689707 } ,
690- Type :: SpecialForm ( special_form) => write ! ( f, "{special_form}" ) ,
691- Type :: KnownInstance ( known_instance) => write ! ( f, "{}" , known_instance. repr( self . db) ) ,
708+ Type :: SpecialForm ( special_form) => {
709+ write ! ( f. with_detail( TypeDetail :: Type ( self . ty) ) , "{special_form}" )
710+ }
711+ Type :: KnownInstance ( known_instance) => write ! (
712+ f. with_detail( TypeDetail :: Type ( self . ty) ) ,
713+ "{}" ,
714+ known_instance. repr( self . db)
715+ ) ,
692716 Type :: FunctionLiteral ( function) => function
693717 . display_with ( self . db , self . settings . clone ( ) )
694718 . fmt_detailed ( f) ,
@@ -724,7 +748,10 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
724748 signatures => {
725749 // TODO: How to display overloads?
726750 if !self . settings . multiline {
727- f. write_str ( "Overload[" ) ?;
751+ // TODO: This should ideally have a TypeDetail but we actually
752+ // don't have a type for @overload (we just detect the decorator)
753+ f. write_str ( "Overload" ) ?;
754+ f. write_char ( '[' ) ?;
728755 }
729756 let separator = if self . settings . multiline { "\n " } else { ", " } ;
730757 let mut join = f. join ( separator) ;
@@ -815,7 +842,9 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
815842 Type :: StringLiteral ( string) => {
816843 write ! ( f, "{}" , string. display_with( self . db, self . settings. clone( ) ) )
817844 }
818- Type :: LiteralString => f. write_str ( "LiteralString" ) ,
845+ Type :: LiteralString => f
846+ . with_detail ( TypeDetail :: Type ( self . ty ) )
847+ . write_str ( "LiteralString" ) ,
819848 Type :: BytesLiteral ( bytes) => {
820849 let escape = AsciiEscape :: with_preferred_quote ( bytes. value ( self . db ) , Quote :: Double ) ;
821850
@@ -831,8 +860,12 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
831860 Type :: TypeVar ( bound_typevar) => {
832861 write ! ( f, "{}" , bound_typevar. identity( self . db) . display( self . db) )
833862 }
834- Type :: AlwaysTruthy => f. write_str ( "AlwaysTruthy" ) ,
835- Type :: AlwaysFalsy => f. write_str ( "AlwaysFalsy" ) ,
863+ Type :: AlwaysTruthy => f
864+ . with_detail ( TypeDetail :: Type ( self . ty ) )
865+ . write_str ( "AlwaysTruthy" ) ,
866+ Type :: AlwaysFalsy => f
867+ . with_detail ( TypeDetail :: Type ( self . ty ) )
868+ . write_str ( "AlwaysFalsy" ) ,
836869 Type :: BoundSuper ( bound_super) => {
837870 f. write_str ( "<super: " ) ?;
838871 Type :: from ( bound_super. pivot_class ( self . db ) )
@@ -845,7 +878,9 @@ impl<'db> FmtDetailed<'db> for DisplayRepresentation<'db> {
845878 f. write_str ( ">" )
846879 }
847880 Type :: TypeIs ( type_is) => {
848- f. write_str ( "TypeIs[" ) ?;
881+ f. with_detail ( TypeDetail :: Type ( Type :: SpecialForm ( SpecialFormType :: TypeIs ) ) )
882+ . write_str ( "TypeIs" ) ?;
883+ f. write_char ( '[' ) ?;
849884 type_is
850885 . return_type ( self . db )
851886 . display_with ( self . db , self . settings . singleline ( ) )
0 commit comments