Skip to content

Commit 5c7e73d

Browse files
authored
Python: Add exception types
1 parent 07a70af commit 5c7e73d

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

python/ql/src/semmle/python/ApiGraphs.qll

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -353,25 +353,44 @@ module API {
353353

354354
/** Returns the names of known built-ins. */
355355
private string builtin_name() {
356-
// Built-in functions shared between Python 2.7.6 and 3.9.5
356+
// Built-in functions and exceptions shared between Python 2 and 3
357357
result in [
358358
"abs", "all", "any", "bin", "bool", "bytearray", "callable", "chr", "classmethod",
359359
"compile", "complex", "delattr", "dict", "dir", "divmod", "enumerate", "eval", "filter",
360360
"float", "format", "frozenset", "getattr", "globals", "hasattr", "hash", "help", "hex",
361361
"id", "input", "int", "isinstance", "issubclass", "iter", "len", "list", "locals", "map",
362362
"max", "memoryview", "min", "next", "object", "oct", "open", "ord", "pow", "print",
363363
"property", "range", "repr", "reversed", "round", "set", "setattr", "slice", "sorted",
364-
"staticmethod", "str", "sum", "super", "tuple", "type", "vars", "zip", "__import__"
364+
"staticmethod", "str", "sum", "super", "tuple", "type", "vars", "zip", "__import__",
365+
// Exceptions
366+
"ArithmeticError", "AssertionError", "AttributeError", "BaseException", "BufferError",
367+
"BytesWarning", "DeprecationWarning", "EOFError", "EnvironmentError", "Exception",
368+
"FloatingPointError", "FutureWarning", "GeneratorExit", "IOError", "ImportError",
369+
"ImportWarning", "IndentationError", "IndexError", "KeyError", "KeyboardInterrupt",
370+
"LookupError", "MemoryError", "NameError", "NotImplemented", "NotImplementedError",
371+
"OSError", "OverflowError", "PendingDeprecationWarning", "ReferenceError", "RuntimeError",
372+
"RuntimeWarning", "StandardError", "StopIteration", "SyntaxError", "SyntaxWarning",
373+
"SystemError", "SystemExit", "TabError", "TypeError", "UnboundLocalError",
374+
"UnicodeDecodeError", "UnicodeEncodeError", "UnicodeError", "UnicodeTranslateError",
375+
"UnicodeWarning", "UserWarning", "ValueError", "Warning", "ZeroDivisionError"
365376
]
366377
or
367-
// Built-in constants shared between Python 2.7.6 and 3.9.5
378+
// Built-in constants shared between Python 2 and 3
368379
result in ["False", "True", "None", "NotImplemented", "Ellipsis", "__debug__"]
369380
or
370-
// Python 3.9.5 only
381+
// Python 3 only
371382
major_version() = 3 and
372-
result in ["ascii", "breakpoint", "bytes", "exec"]
383+
result in [
384+
"ascii", "breakpoint", "bytes", "exec",
385+
// Exceptions
386+
"BlockingIOError", "BrokenPipeError", "ChildProcessError", "ConnectionAbortedError",
387+
"ConnectionError", "ConnectionRefusedError", "ConnectionResetError", "FileExistsError",
388+
"FileNotFoundError", "InterruptedError", "IsADirectoryError", "ModuleNotFoundError",
389+
"NotADirectoryError", "PermissionError", "ProcessLookupError", "RecursionError",
390+
"ResourceWarning", "StopAsyncIteration", "TimeoutError"
391+
]
373392
or
374-
// Python 2.7.6 only
393+
// Python 2 only
375394
major_version() = 2 and
376395
result in [
377396
"basestring", "cmp", "execfile", "file", "long", "raw_input", "reduce", "reload",

0 commit comments

Comments
 (0)