Commit b9d10d08 authored by Alexander Belopolsky's avatar Alexander Belopolsky

Issue #10386: Added __all__ to token module; this simplifies importing

in tokenize module and prevents leaking of private names through
import *.
parent bb27c128
#! /usr/bin/env python3
"""Token constants (from "token.h").""" """Token constants (from "token.h")."""
__all__ = ['tok_name', 'ISTERMINAL', 'ISNONTERMINAL', 'ISEOF']
# This file is automatically generated; please don't muck it up! # This file is automatically generated; please don't muck it up!
# #
# To update the symbols in this file, 'cd' to the top directory of # To update the symbols in this file, 'cd' to the top directory of
...@@ -68,12 +68,10 @@ N_TOKENS = 55 ...@@ -68,12 +68,10 @@ N_TOKENS = 55
NT_OFFSET = 256 NT_OFFSET = 256
#--end constants-- #--end constants--
tok_name = {} tok_name = {value: name
for _name, _value in list(globals().items()): for name, value in globals().items()
if type(_value) is type(0): if isinstance(value, int)}
tok_name[_value] = _name __all__.extend(tok_name.values())
del _name, _value
def ISTERMINAL(x): def ISTERMINAL(x):
return x < NT_OFFSET return x < NT_OFFSET
...@@ -85,7 +83,7 @@ def ISEOF(x): ...@@ -85,7 +83,7 @@ def ISEOF(x):
return x == ENDMARKER return x == ENDMARKER
def main(): def _main():
import re import re
import sys import sys
args = sys.argv[1:] args = sys.argv[1:]
...@@ -139,4 +137,4 @@ def main(): ...@@ -139,4 +137,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() _main()
...@@ -33,9 +33,8 @@ from io import TextIOWrapper ...@@ -33,9 +33,8 @@ from io import TextIOWrapper
cookie_re = re.compile("coding[:=]\s*([-\w.]+)") cookie_re = re.compile("coding[:=]\s*([-\w.]+)")
import token import token
__all__ = [x for x in dir(token) if not x.startswith("_")] __all__ = token.__all__ + ["COMMENT", "tokenize", "detect_encoding",
__all__.extend(["COMMENT", "tokenize", "detect_encoding", "NL", "untokenize", "NL", "untokenize", "ENCODING", "TokenInfo"]
"ENCODING", "TokenInfo"])
del token del token
COMMENT = N_TOKENS COMMENT = N_TOKENS
......
...@@ -63,6 +63,10 @@ Core and Builtins ...@@ -63,6 +63,10 @@ Core and Builtins
Library Library
------- -------
- Issue #10386: Add __all__ to token module; this simplifies importing
in tokenize module and prevents leaking of private names through
import *.
- Issue #4471: Properly shutdown socket in IMAP.shutdown(). Patch by - Issue #4471: Properly shutdown socket in IMAP.shutdown(). Patch by
Lorenzo M. Catucci. Lorenzo M. Catucci.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment