Skip to content

Commit 3525e83

Browse files
Add changenote + some doc updates
1 parent 871688f commit 3525e83

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

python/ql/src/Functions/IncorrectRaiseInSpecialMethod.qhelp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ Therefore, if a method is unable to perform the expected operation then its resp
2020
</p>
2121

2222
<ul>
23-
<li>Attribute access, <code>a.b</code> (<code>__getattr__</code>): Raise <code>AttributeError</code></li>
23+
<li>Attribute access, <code>a.b</code> (<code>__getattr__</code>): Raise <code>AttributeError</code>.</li>
2424
<li>Arithmetic operations, <code>a + b</code> (<code>__add__</code>): Do not raise an exception, return <code>NotImplemented</code> instead.</li>
2525
<li>Indexing, <code>a[b]</code> (<code>__getitem__</code>): Raise <code>KeyError</code> or <code>IndexError</code>.</li>
2626
<li>Hashing, <code>hash(a)</code> (<code>__hash__</code>): Should not raise an exception. Use <code>__hash__ = None</code> to indicate that an object is unhashable rather than raising an exception.</li>
2727
<li>Equality methods, <code>a == b</code> (<code>__eq__</code>): Never raise an exception, always return <code>True</code> or <code>False</code>.</li>
2828
<li>Ordering comparison methods, <code>a &lt; b</code> (<code>__lt__</code>): Raise a <code>TypeError</code> if the objects cannot be ordered.</li>
29-
<li>Most others: Ideally, do not implement the method at all, otherwise raise <code>TypeError</code> to indicate that the operation is unsupported.</li>
29+
<li>Most others: If the operation is never supported, the method often does not need to be implemented at all; otherwise a <code>TypeError</code> should be raised.</li>
3030
</ul>
3131

3232
</overview>
3333
<recommendation>
34-
<p>If the method is intended to be abstract, then declare it so using the <code>@abstractmethod</code> decorator.
34+
<p>If the method is intended to be abstract, and thus always raise an exception, then declare it so using the <code>@abstractmethod</code> decorator.
3535
Otherwise, either remove the method or ensure that the method raises an exception of the correct type.
3636
</p>
3737

python/ql/src/Functions/IncorrectRaiseInSpecialMethod.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ predicate preferredRaise(string name, string execName, string message) {
9494
}
9595

9696
predicate execIsOfType(Expr exec, string execName) {
97-
// Might make sense to have execName be an IPA type here. Or part of a more general API modelling builtin/stdlib subclass relations.
97+
// Might make sense to have execName be an IPA type here. Or part of a more general API modeling builtin/stdlib subclass relations.
9898
exists(string subclass |
9999
execName = "TypeError" and
100100
subclass = "TypeError"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The `py/unexpected-raise-in-special-method` query has been modernized. It produces additional results in cases where the exception is
5+
only raised conditionally. Its precision has been changed from `very-high` to `high`.

0 commit comments

Comments
 (0)