bpo-35733: Make isinstance(ast.Constant(boolean), ast.Num) be false. (GH-11547)

This commit is contained in:
Anthony Sottile 2019-01-18 11:30:28 -08:00 committed by Serhiy Storchaka
parent 39ed289a35
commit 7417622617
3 changed files with 13 additions and 1 deletions

View file

@ -346,7 +346,10 @@ class _ABC(type):
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):
@ -384,3 +387,6 @@ _const_types = {
NameConstant: (type(None), bool),
Ellipsis: (type(...),),
}
_const_types_not = {
Num: (bool,),
}