Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/ql/src/Functions/IncorrectRaiseInSpecialMethod.ql
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ private predicate ordering_method(string name) {
private predicate cast_method(string name) {
name = "__nonzero__" and major_version() = 2
or
name = "__bool__"
or
name = "__int__"
or
name = "__float__"
Expand Down Expand Up @@ -118,6 +116,8 @@ predicate preferred_raise(string name, ClassObject ex) {
ordering_method(name) and ex = theTypeErrorType()
or
arithmetic_method(name) and ex = Object::builtin("ArithmeticError")
or
name = "__bool__" and ex = theTypeErrorType()
}

predicate no_need_to_raise(string name, string message) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
| protocols.py:98:5:98:33 | Function __getitem__ | Function always raises $@; raise LookupError instead | file://:Compiled Code:0:0:0:0 | builtin-class ZeroDivisionError | builtin-class ZeroDivisionError |
| protocols.py:101:5:101:26 | Function __getattr__ | Function always raises $@; raise AttributeError instead | file://:Compiled Code:0:0:0:0 | builtin-class ZeroDivisionError | builtin-class ZeroDivisionError |
| protocols.py:104:5:104:23 | Function __bool__ | Function always raises $@; raise TypeError instead | file://:Compiled Code:0:0:0:0 | builtin-class ZeroDivisionError | builtin-class ZeroDivisionError |
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
| om_test.py:71:5:71:19 | Function WrongSpecials.__repr__ | Too few parameters for special method __repr__, which has no parameters, but should have 1, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
| om_test.py:74:5:74:46 | Function WrongSpecials.__add__ | 1 default values(s) will never be used for special method __add__, in class $@. | om_test.py:57:1:57:28 | class WrongSpecials | WrongSpecials |
| om_test.py:97:15:97:34 | Function NotOKSpecials.lambda | Too few parameters for special method __sub__, which has 1 parameter, but should have 2, in class $@. | om_test.py:95:1:95:28 | class NotOKSpecials | NotOKSpecials |
| protocols.py:104:1:104:12 | Function f | Too few parameters for special method __add__, which has 1 parameter, but should have 2, in class $@. | protocols.py:107:1:107:29 | class MissingMethods | MissingMethods |
| protocols.py:104:1:104:12 | Function f | Too few parameters for special method __set__, which has 1 parameter, but should have 3, in class $@. | protocols.py:107:1:107:29 | class MissingMethods | MissingMethods |
| protocols.py:107:1:107:12 | Function f | Too few parameters for special method __add__, which has 1 parameter, but should have 2, in class $@. | protocols.py:110:1:110:29 | class MissingMethods | MissingMethods |
| protocols.py:107:1:107:12 | Function f | Too few parameters for special method __set__, which has 1 parameter, but should have 3, in class $@. | protocols.py:110:1:110:29 | class MissingMethods | MissingMethods |
8 changes: 8 additions & 0 deletions python/ql/test/query-tests/Functions/general/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def __getitem__(self, index):
def __getattr__(self):
raise ZeroDivisionError()

def __bool__(self):
raise ZeroDivisionError()

def f(self):
pass

Expand All @@ -116,3 +119,8 @@ class OK(object):
def __call__(self):
yield 0
raise StopIteration

# __bool__ returns `True` by default, so raising `TypeError` should not give an alert
# FP reported in https://github.com/github/codeql/issues/2388
def __bool__(self):
raise TypeError