From 4bc10b9f41c29cfc8c093b6d7c2505894c6e40ca Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 8 Mar 2024 10:14:49 +0100 Subject: [PATCH] Move list of builtins from Symtab.py into Code.py, next to the list of version specific builtins. See https://github.com/cython/cython/pull/6043/ --- Cython/Compiler/Code.py | 158 ++++++++++++++++++++++++++ Cython/Compiler/Symtab.py | 161 +-------------------------- Cython/Compiler/Tests/TestBuiltin.py | 2 +- 3 files changed, 161 insertions(+), 160 deletions(-) diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index 2146e9bf638..012c409fea2 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -53,6 +53,164 @@ 'PyTypeObject': 'PyHeapTypeObject', } +# Builtins as of Python 3.12.0 +KNOWN_PYTHON_BUILTINS_VERSION = (3, 12, 0, 'final', 0) +KNOWN_PYTHON_BUILTINS = frozenset([ + 'ArithmeticError', + 'AssertionError', + 'AttributeError', + 'BaseException', + 'BaseExceptionGroup', + 'BlockingIOError', + 'BrokenPipeError', + 'BufferError', + 'BytesWarning', + 'ChildProcessError', + 'ConnectionAbortedError', + 'ConnectionError', + 'ConnectionRefusedError', + 'ConnectionResetError', + 'DeprecationWarning', + 'EOFError', + 'Ellipsis', + 'EncodingWarning', + 'EnvironmentError', + 'Exception', + 'ExceptionGroup', + 'False', + 'FileExistsError', + 'FileNotFoundError', + 'FloatingPointError', + 'FutureWarning', + 'GeneratorExit', + 'IOError', + 'ImportError', + 'ImportWarning', + 'IndentationError', + 'IndexError', + 'InterruptedError', + 'IsADirectoryError', + 'KeyError', + 'KeyboardInterrupt', + 'LookupError', + 'MemoryError', + 'ModuleNotFoundError', + 'NameError', + 'None', + 'NotADirectoryError', + 'NotImplemented', + 'NotImplementedError', + 'OSError', + 'OverflowError', + 'PendingDeprecationWarning', + 'PermissionError', + 'ProcessLookupError', + 'RecursionError', + 'ReferenceError', + 'ResourceWarning', + 'RuntimeError', + 'RuntimeWarning', + 'StopAsyncIteration', + 'StopIteration', + 'SyntaxError', + 'SyntaxWarning', + 'SystemError', + 'SystemExit', + 'TabError', + 'TimeoutError', + 'True', + 'TypeError', + 'UnboundLocalError', + 'UnicodeDecodeError', + 'UnicodeEncodeError', + 'UnicodeError', + 'UnicodeTranslateError', + 'UnicodeWarning', + 'UserWarning', + 'ValueError', + 'Warning', + 'WindowsError', + 'ZeroDivisionError', + '__build_class__', + '__debug__', + '__import__', + 'abs', + 'aiter', + 'all', + 'anext', + 'any', + 'ascii', + 'bin', + 'bool', + 'breakpoint', + 'bytearray', + 'bytes', + 'callable', + 'chr', + 'classmethod', + 'compile', + 'complex', + 'copyright', + 'credits', + 'delattr', + 'dict', + 'dir', + 'divmod', + 'enumerate', + 'eval', + 'exec', + 'exit', + 'filter', + 'float', + 'format', + 'frozenset', + 'getattr', + 'globals', + 'hasattr', + 'hash', + 'help', + 'hex', + 'id', + 'input', + 'int', + 'isinstance', + 'issubclass', + 'iter', + 'len', + 'license', + 'list', + 'locals', + 'map', + 'max', + 'memoryview', + 'min', + 'next', + 'object', + 'oct', + 'open', + 'ord', + 'pow', + 'print', + 'property', + 'quit', + 'range', + 'repr', + 'reversed', + 'round', + 'set', + 'setattr', + 'slice', + 'sorted', + 'staticmethod', + 'str', + 'sum', + 'super', + 'tuple', + 'type', + 'vars', + 'zip', +]) + uncachable_builtins = [ # Global/builtin names that cannot be cached because they may or may not # be available at import time, for various reasons: diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index f0f554ef844..3137861dade 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -29,163 +29,6 @@ '_Bool', '_Complex'', _Imaginary', 'inline', 'restrict', } -# Builtins as of Python 3.12.0 -KNOWN_PYTHON_BUILTINS_VERSION = (3, 12, 0, 'final', 0) -KNOWN_PYTHON_BUILTINS = frozenset([ - 'ArithmeticError', - 'AssertionError', - 'AttributeError', - 'BaseException', - 'BaseExceptionGroup', - 'BlockingIOError', - 'BrokenPipeError', - 'BufferError', - 'BytesWarning', - 'ChildProcessError', - 'ConnectionAbortedError', - 'ConnectionError', - 'ConnectionRefusedError', - 'ConnectionResetError', - 'DeprecationWarning', - 'EOFError', - 'Ellipsis', - 'EncodingWarning', - 'EnvironmentError', - 'Exception', - 'ExceptionGroup', - 'False', - 'FileExistsError', - 'FileNotFoundError', - 'FloatingPointError', - 'FutureWarning', - 'GeneratorExit', - 'IOError', - 'ImportError', - 'ImportWarning', - 'IndentationError', - 'IndexError', - 'InterruptedError', - 'IsADirectoryError', - 'KeyError', - 'KeyboardInterrupt', - 'LookupError', - 'MemoryError', - 'ModuleNotFoundError', - 'NameError', - 'None', - 'NotADirectoryError', - 'NotImplemented', - 'NotImplementedError', - 'OSError', - 'OverflowError', - 'PendingDeprecationWarning', - 'PermissionError', - 'ProcessLookupError', - 'RecursionError', - 'ReferenceError', - 'ResourceWarning', - 'RuntimeError', - 'RuntimeWarning', - 'StopAsyncIteration', - 'StopIteration', - 'SyntaxError', - 'SyntaxWarning', - 'SystemError', - 'SystemExit', - 'TabError', - 'TimeoutError', - 'True', - 'TypeError', - 'UnboundLocalError', - 'UnicodeDecodeError', - 'UnicodeEncodeError', - 'UnicodeError', - 'UnicodeTranslateError', - 'UnicodeWarning', - 'UserWarning', - 'ValueError', - 'Warning', - 'WindowsError', - 'ZeroDivisionError', - '__build_class__', - '__debug__', - '__import__', - 'abs', - 'aiter', - 'all', - 'anext', - 'any', - 'ascii', - 'bin', - 'bool', - 'breakpoint', - 'bytearray', - 'bytes', - 'callable', - 'chr', - 'classmethod', - 'compile', - 'complex', - 'copyright', - 'credits', - 'delattr', - 'dict', - 'dir', - 'divmod', - 'enumerate', - 'eval', - 'exec', - 'exit', - 'filter', - 'float', - 'format', - 'frozenset', - 'getattr', - 'globals', - 'hasattr', - 'hash', - 'help', - 'hex', - 'id', - 'input', - 'int', - 'isinstance', - 'issubclass', - 'iter', - 'len', - 'license', - 'list', - 'locals', - 'map', - 'max', - 'memoryview', - 'min', - 'next', - 'object', - 'oct', - 'open', - 'ord', - 'pow', - 'print', - 'property', - 'quit', - 'range', - 'repr', - 'reversed', - 'round', - 'set', - 'setattr', - 'slice', - 'sorted', - 'staticmethod', - 'str', - 'sum', - 'super', - 'tuple', - 'type', - 'vars', - 'zip', -]) def c_safe_identifier(cname): # There are some C limitations on struct entry names. @@ -1345,7 +1188,7 @@ def lookup(self, name, language_level=None, str_is_str=None): return Scope.lookup(self, name) def declare_builtin(self, name, pos): - if name not in KNOWN_PYTHON_BUILTINS: + if name not in Code.KNOWN_PYTHON_BUILTINS: if self.outer_scope is not None: return self.outer_scope.declare_builtin(name, pos) else: @@ -1513,7 +1356,7 @@ def declare_tuple_type(self, pos, components): return entry def declare_builtin(self, name, pos): - if name not in KNOWN_PYTHON_BUILTINS \ + if name not in Code.KNOWN_PYTHON_BUILTINS \ and name not in Code.renamed_py2_builtins_map \ and name not in Code.uncachable_builtins: if self.has_import_star: diff --git a/Cython/Compiler/Tests/TestBuiltin.py b/Cython/Compiler/Tests/TestBuiltin.py index 6a70afbc636..831f0e0aaa6 100644 --- a/Cython/Compiler/Tests/TestBuiltin.py +++ b/Cython/Compiler/Tests/TestBuiltin.py @@ -7,7 +7,7 @@ builtin_scope, ) -from ..Symtab import ( +from ..Code import ( KNOWN_PYTHON_BUILTINS_VERSION, KNOWN_PYTHON_BUILTINS, )