Skip to content

Commit

Permalink
Move list of builtins from Symtab.py into Code.py, next to the list o…
Browse files Browse the repository at this point in the history
…f version specific builtins.

See #6043
  • Loading branch information
scoder committed Mar 8, 2024
1 parent da405c6 commit 4bc10b9
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 160 deletions.
158 changes: 158 additions & 0 deletions Cython/Compiler/Code.py
Expand Up @@ -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:
Expand Down
161 changes: 2 additions & 159 deletions Cython/Compiler/Symtab.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Cython/Compiler/Tests/TestBuiltin.py
Expand Up @@ -7,7 +7,7 @@
builtin_scope,
)

from ..Symtab import (
from ..Code import (
KNOWN_PYTHON_BUILTINS_VERSION, KNOWN_PYTHON_BUILTINS,
)

Expand Down

0 comments on commit 4bc10b9

Please sign in to comment.