summaryrefslogtreecommitdiffstats
path: root/Lib/token.py
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-11-11 14:07:41 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2010-11-11 14:07:41 (GMT)
commitb9d10d08c4eb0dedaea3b1bcde0f13b033e16c85 (patch)
treeac679156d755c597b585a4d0d346919ea2cb3e84 /Lib/token.py
parentbb27c128a5524470673618c40a2043e0cfaf96a4 (diff)
downloadcpython-b9d10d08c4eb0dedaea3b1bcde0f13b033e16c85.zip
cpython-b9d10d08c4eb0dedaea3b1bcde0f13b033e16c85.tar.gz
cpython-b9d10d08c4eb0dedaea3b1bcde0f13b033e16c85.tar.bz2
Issue #10386: Added __all__ to token module; this simplifies importing
in tokenize module and prevents leaking of private names through import *.
Diffstat (limited to 'Lib/token.py')
-rwxr-xr-xLib/token.py18
1 files changed, 8 insertions, 10 deletions
diff --git a/Lib/token.py b/Lib/token.py
index a48bf3c..7e2bfcf 100755
--- a/Lib/token.py
+++ b/Lib/token.py
@@ -1,7 +1,7 @@
-#! /usr/bin/env python3
-
"""Token constants (from "token.h")."""
+__all__ = ['tok_name', 'ISTERMINAL', 'ISNONTERMINAL', 'ISEOF']
+
# This file is automatically generated; please don't muck it up!
#
# To update the symbols in this file, 'cd' to the top directory of
@@ -68,12 +68,10 @@ N_TOKENS = 55
NT_OFFSET = 256
#--end constants--
-tok_name = {}
-for _name, _value in list(globals().items()):
- if type(_value) is type(0):
- tok_name[_value] = _name
-del _name, _value
-
+tok_name = {value: name
+ for name, value in globals().items()
+ if isinstance(value, int)}
+__all__.extend(tok_name.values())
def ISTERMINAL(x):
return x < NT_OFFSET
@@ -85,7 +83,7 @@ def ISEOF(x):
return x == ENDMARKER
-def main():
+def _main():
import re
import sys
args = sys.argv[1:]
@@ -139,4 +137,4 @@ def main():
if __name__ == "__main__":
- main()
+ _main()