summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ast.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-10-28 11:43:03 (GMT)
committerGitHub <noreply@github.com>2018-10-28 11:43:03 (GMT)
commit6015cc50bc38b9e920ce4986ee10658eaa14f561 (patch)
treeeeae07dc8d901b5295b10c11c98a96205415bade /Lib/test/test_ast.py
parent913876d824d969f8c7431e8a9d4610a9a11a786e (diff)
downloadcpython-6015cc50bc38b9e920ce4986ee10658eaa14f561.zip
cpython-6015cc50bc38b9e920ce4986ee10658eaa14f561.tar.gz
cpython-6015cc50bc38b9e920ce4986ee10658eaa14f561.tar.bz2
bpo-32892: Support subclasses of base types in isinstance checks for AST constants. (GH-9934)
Some projects (e.g. Chameleon) create ast.Str containing an instance of the str subclass.
Diffstat (limited to 'Lib/test/test_ast.py')
-rw-r--r--Lib/test/test_ast.py4
1 files changed, 4 insertions, 0 deletions
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):