except AttributeError:
return False
else:
- return isinstance(value, _const_types[cls])
+ return (
+ isinstance(value, _const_types[cls]) and
+ not isinstance(value, _const_types_not.get(cls, ()))
+ )
return type.__instancecheck__(cls, inst)
def _new(cls, *args, **kwargs):
NameConstant: (type(None), bool),
Ellipsis: (type(...),),
}
+_const_types_not = {
+ Num: (bool,),
+}
self.assertFalse(isinstance(ast.Str('42'), ast.Bytes))
self.assertFalse(isinstance(ast.Num(42), ast.NameConstant))
self.assertFalse(isinstance(ast.Num(42), ast.Ellipsis))
+ self.assertFalse(isinstance(ast.NameConstant(True), ast.Num))
+ self.assertFalse(isinstance(ast.NameConstant(False), ast.Num))
self.assertFalse(isinstance(ast.Constant('42'), ast.Num))
self.assertFalse(isinstance(ast.Constant(42), ast.Str))
self.assertFalse(isinstance(ast.Constant('42'), ast.Bytes))
self.assertFalse(isinstance(ast.Constant(42), ast.NameConstant))
self.assertFalse(isinstance(ast.Constant(42), ast.Ellipsis))
+ self.assertFalse(isinstance(ast.Constant(True), ast.Num))
+ self.assertFalse(isinstance(ast.Constant(False), ast.Num))
self.assertFalse(isinstance(ast.Constant(), ast.Num))
self.assertFalse(isinstance(ast.Constant(), ast.Str))