##// END OF EJS Templates
Simplify test_ident using str.isidentifier()...
Thomas Kluyver -
Show More
@@ -46,13 +46,10 b' lines = [line_to_tuple(line) for line in lines]'
46 print('Filtering out characters that are not valid Python 3 identifiers')
46 print('Filtering out characters that are not valid Python 3 identifiers')
47
47
48 def test_ident(i):
48 def test_ident(i):
49 """Is the unicode string a valid Python 3 identifer."""
49 """Is the unicode string valid in a Python 3 identifer."""
50 try:
50 # Some characters are not valid at the start of a name, but we still want to
51 exec('a%s = 10' % i, {}, {})
51 # include them. So prefix with 'a', which is valid at the start.
52 except SyntaxError:
52 return ('a' + i).isidentifier()
53 return False
54 else:
55 return True
56
53
57 assert test_ident("α")
54 assert test_ident("α")
58 assert not test_ident('‴')
55 assert not test_ident('‴')
General Comments 0
You need to be logged in to leave comments. Login now