@@ -24,8 +24,6 @@ internal class TypeManager
2424 internal static IPythonBaseTypeProvider pythonBaseTypeProvider ;
2525#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
2626
27-
28- private const BindingFlags tbFlags = BindingFlags . Public | BindingFlags . Static ;
2927 private static readonly Dictionary < MaybeType , PyType > cache = new ( ) ;
3028
3129 static readonly Dictionary < PyType , SlotsHolder > _slotsHolders = new ( PythonReferenceComparer . Instance ) ;
@@ -654,39 +652,32 @@ static void InheritSubstructs(IntPtr type)
654652 /// </summary>
655653 internal static void InitializeSlots ( PyType type , Type impl , SlotsHolder ? slotsHolder = null )
656654 {
657- // We work from the most-derived class up; make sure to get
658- // the most-derived slot and not to override it with a base
659- // class's slot.
655+ // FlattenHierarchy provides inherited public static methods for slot lookup.
660656 var seen = new HashSet < string > ( ) ;
657+ MethodInfo [ ] methods = impl . GetMethods ( BindingFlags . Public | BindingFlags . Static | BindingFlags . FlattenHierarchy ) ;
661658
662- while ( impl != null )
659+ foreach ( MethodInfo method in methods )
663660 {
664- MethodInfo [ ] methods = impl . GetMethods ( tbFlags | BindingFlags . DeclaredOnly ) ;
665- foreach ( MethodInfo method in methods )
661+ string name = method . Name ;
662+ if ( ! name . StartsWith ( "tp_" ) && ! TypeOffset . IsSupportedSlotName ( name ) )
666663 {
667- string name = method . Name ;
668- if ( ! name . StartsWith ( "tp_" ) && ! TypeOffset . IsSupportedSlotName ( name ) )
669- {
670- Debug . Assert ( ! name . Contains ( "_" ) || name . StartsWith ( "_" ) || method . IsSpecialName ) ;
671- continue ;
672- }
673-
674- if ( seen . Contains ( name ) )
675- {
676- continue ;
677- }
678-
679- InitializeSlot ( type , Interop . GetThunk ( method ) , name , slotsHolder ) ;
664+ Debug . Assert ( ! name . Contains ( "_" ) || name . StartsWith ( "_" ) || method . IsSpecialName ) ;
665+ continue ;
666+ }
680667
681- seen . Add ( name ) ;
668+ if ( seen . Contains ( name ) )
669+ {
670+ continue ;
682671 }
683672
684- var initSlot = impl . GetMethod ( "InitializeSlots" , BindingFlags . Static | BindingFlags . Public ) ;
685- initSlot ? . Invoke ( null , parameters : new object ? [ ] { type , seen , slotsHolder } ) ;
673+ InitializeSlot ( type , Interop . GetThunk ( method ) , name , slotsHolder ) ;
686674
687- impl = impl . BaseType ;
675+ seen . Add ( name ) ;
688676 }
689677
678+ var initSlot = impl . GetMethod ( "InitializeSlots" , BindingFlags . Static | BindingFlags . Public | BindingFlags . DeclaredOnly ) ;
679+ initSlot ? . Invoke ( null , parameters : new object ? [ ] { type , seen , slotsHolder } ) ;
680+
690681 SetRequiredSlots ( type , seen ) ;
691682 }
692683
0 commit comments