Skip to content

Commit 7ea19b0

Browse files
Merged in bugfix (pull request labscript-suite#31)
Fix issue labscript-suite#65 - cannot create globals in latest Python releases.
2 parents cdfae0e + 005a931 commit 7ea19b0

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

__init__.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,21 @@ def is_valid_python_identifier(name):
5353
import StringIO as io
5454
else:
5555
import io
56+
# No whitespace allowed. Do this check here because an actual newline in the source
57+
# is not easily distinguished from a NEWLINE token in the produced tokens, which is
58+
# produced even when there is no newline character in the string. So since we ignore
59+
# NEWLINE later, we must check for it now.
60+
if name != "".join(name.split()):
61+
return False
5662
try:
5763
tokens = list(tokenize.generate_tokens(io.StringIO(name).readline))
5864
except tokenize.TokenError:
5965
return False
60-
if len(tokens) == 2:
61-
(token_type, _, _, _, _), _ = tokens
62-
return token_type == tokenize.NAME
66+
token_types = [
67+
t[0] for t in tokens if t[0] not in [tokenize.NEWLINE, tokenize.ENDMARKER]
68+
]
69+
if len(token_types) == 1:
70+
return token_types[0] == tokenize.NAME
6371
return False
6472

6573

0 commit comments

Comments
 (0)