diff options
-rw-r--r-- | Lib/ast.py | 2 | ||||
-rw-r--r-- | Lib/test/test_ast.py | 4 |
2 files changed, 5 insertions, 1 deletions
@@ -346,7 +346,7 @@ class _ABC(type): except AttributeError: return False else: - return type(value) in _const_types[cls] + return isinstance(value, _const_types[cls]) return type.__instancecheck__(cls, inst) def _new(cls, *args, **kwargs): diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 10be02e..4bbdc3b 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -399,6 +399,10 @@ class AST_Tests(unittest.TestCase): self.assertFalse(isinstance(ast.Constant(), ast.NameConstant)) self.assertFalse(isinstance(ast.Constant(), ast.Ellipsis)) + class S(str): pass + self.assertTrue(isinstance(ast.Constant(S('42')), ast.Str)) + self.assertFalse(isinstance(ast.Constant(S('42')), ast.Num)) + def test_subclasses(self): class N(ast.Num): def __init__(self, *args, **kwargs): |