@@ -12,8 +12,8 @@ use crate::{
1212 pyclass:: { PyClassImpl , StaticType } ,
1313 pyobject:: PyLease ,
1414 types:: { Callable , GetAttr , PyTypeFlags , PyTypeSlots , SetAttr } ,
15- IdProtocol , PyContext , PyObject , PyObjectRef , PyObjectWeak , PyRef , PyResult , PyValue ,
16- TypeProtocol , VirtualMachine ,
15+ IdProtocol , PyContext , PyObjectRef , PyObjectWeak , PyRef , PyResult , PyValue , TypeProtocol ,
16+ VirtualMachine ,
1717} ;
1818use itertools:: Itertools ;
1919use std:: {
@@ -209,8 +209,11 @@ impl PyType {
209209}
210210
211211impl PyTypeRef {
212+ /// Determines if `subclass` is actually a subclass of `cls`, this doesn't call __subclasscheck__,
213+ /// so only use this if `cls` is known to have not overridden the base __subclasscheck__ magic
214+ /// method.
212215 pub fn issubclass ( & self , cls : & impl Borrow < crate :: PyObject > ) -> bool {
213- self . _issubclass ( cls)
216+ self . as_object ( ) . is ( cls. borrow ( ) ) || self . mro . iter ( ) . any ( |c| c . is ( cls . borrow ( ) ) )
214217 }
215218
216219 pub fn iter_mro ( & self ) -> impl Iterator < Item = & PyTypeRef > + DoubleEndedIterator {
@@ -788,36 +791,6 @@ pub(crate) fn init(ctx: &PyContext) {
788791 PyType :: extend_class ( ctx, & ctx. types . type_type ) ;
789792}
790793
791- impl PyLease < ' _ , PyType > {
792- pub fn issubclass ( & self , cls : & impl Borrow < crate :: PyObject > ) -> bool {
793- self . _issubclass ( cls)
794- }
795- }
796-
797- pub trait DerefToPyType : Borrow < PyObject > {
798- fn deref_to_type ( & self ) -> & PyType ;
799-
800- /// Determines if `subclass` is actually a subclass of `cls`, this doesn't call __subclasscheck__,
801- /// so only use this if `cls` is known to have not overridden the base __subclasscheck__ magic
802- /// method.
803- fn _issubclass ( & self , cls : & impl Borrow < crate :: PyObject > ) -> bool {
804- self . borrow ( ) . is ( cls. borrow ( ) )
805- || self . deref_to_type ( ) . mro . iter ( ) . any ( |c| c. is ( cls. borrow ( ) ) )
806- }
807- }
808-
809- impl DerefToPyType for PyTypeRef {
810- fn deref_to_type ( & self ) -> & PyType {
811- self . deref ( )
812- }
813- }
814-
815- impl < ' a > DerefToPyType for PyLease < ' a , PyType > {
816- fn deref_to_type ( & self ) -> & PyType {
817- self . deref ( )
818- }
819- }
820-
821794pub ( crate ) fn call_slot_new (
822795 typ : PyTypeRef ,
823796 subtype : PyTypeRef ,
0 commit comments