File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -909,6 +909,21 @@ def __subclasscheck__(cls, sub):
909909 self .assertIsSubclass (int , x )
910910 self .assertRaises (ZeroDivisionError , issubclass , list , x )
911911
912+ def test_custom_instancecheck (self ):
913+ class CustomIsInstanceMeta (type ):
914+ def __instancecheck__ (cls , instance ):
915+ return type (instance ) is int
916+
917+ class CustomIsInstance (metaclass = CustomIsInstanceMeta ):
918+ ...
919+
920+ class CustomIsInstanceSubclass (CustomIsInstance ):
921+ ...
922+
923+ self .assertTrue (isinstance (5 , CustomIsInstance ))
924+ self .assertFalse (isinstance (CustomIsInstance (), CustomIsInstance ))
925+ self .assertFalse (isinstance (CustomIsInstanceSubclass (), CustomIsInstance ))
926+
912927 def test_or_type_operator_with_TypeVar (self ):
913928 TV = typing .TypeVar ('T' )
914929 self .assertEqual (TV | str , typing .Union [TV , str ])
You can’t perform that action at this time.
0 commit comments