Skip to content

Commit 97cf15a

Browse files
Merge pull request #20052 from joefarebrother/python-qual-minor-doc-updates
Python: Minor documantation updates to several quality queries
2 parents 8238746 + 0f5be2d commit 97cf15a

14 files changed

+32
-31
lines changed

python/ql/src/Exceptions/CatchingBaseException.qhelp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ leaving <code>KeyboardInterrupt</code> to propagate.
4545
</example>
4646
<references>
4747

48-
<li>Python Language Reference: <a href="http://docs.python.org/2.7/reference/compound_stmts.html#try">The try statement</a>,
49-
<a href="http://docs.python.org/2.7/reference/executionmodel.html#exceptions">Exceptions</a>.</li>
48+
<li>Python Language Reference: <a href="http://docs.python.org/3/reference/compound_stmts.html#try">The try statement</a>,
49+
<a href="http://docs.python.org/3/reference/executionmodel.html#exceptions">Exceptions</a>.</li>
5050
<li>M. Lutz, Learning Python, Section 35.3: Exception Design Tips and Gotchas, O'Reilly Media, 2013.</li>
51-
<li>Python Tutorial: <a href="https://docs.python.org/2/tutorial/errors.html">Errors and Exceptions</a>.</li>
51+
<li>Python Tutorial: <a href="https://docs.python.org/3/tutorial/errors.html">Errors and Exceptions</a>.</li>
5252

5353

5454
</references>

python/ql/src/Exceptions/EmptyExcept.qhelp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
The loss of information can lead to hard to debug errors and incomplete log files.
88
It is even possible that ignoring an exception can cause a security vulnerability.
99
An empty <code>except</code> block may be an indication that the programmer intended to
10-
handle the exception but never wrote the code to do so.</p>
10+
handle the exception, but never wrote the code to do so.</p>
1111

1212
</overview>
1313
<recommendation>
1414
<p>Ensure all exceptions are handled correctly.</p>
1515

1616
</recommendation>
1717
<example>
18-
<p>In this example the program keeps running with the same privileges if it fails to drop to lower
18+
<p>In this example, the program keeps running with the same privileges if it fails to drop to lower
1919
privileges.</p>
2020
<sample src="EmptyExcept.py" />
2121

python/ql/src/Expressions/CallToSuperWrongClass.qhelp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ However, this may result in incorrect object initialization if the enclosing cla
2424
</recommendation>
2525
<example>
2626
<p>
27-
In this example the call to <code>super(Vehicle, self)</code> in <code>Car.__init__</code> is incorrect as it
27+
In this example, the call to <code>super(Vehicle, self)</code> in <code>Car.__init__</code> is incorrect, as it
2828
passes <code>Vehicle</code> rather than <code>Car</code> as the first argument to <code>super</code>.
2929
As a result, <code>super(SportsCar, self).__init__()</code> in the <code>SportsCar.__init__</code> method will not call
3030
all <code>__init__()</code> methods because the call to <code>super(Vehicle, self).__init__()</code>
@@ -37,7 +37,7 @@ skips <code>StatusSymbol.__init__()</code>.
3737
</example>
3838
<references>
3939

40-
<li>Python Standard Library: <a href="https://docs.python.org/2/library/functions.html#super">super</a>.</li>
40+
<li>Python Standard Library: <a href="https://docs.python.org/3/library/functions.html#super">super</a>.</li>
4141
<li>Artima Developer: <a href="http://www.artima.com/weblogs/viewpost.jsp?thread=236275">Things to Know About Python Super</a>.</li>
4242

4343

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
dictionary = {1:"a", 2:"b", 2:"c"}
2-
print dictionary[2]
1+
dictionary = {1:"a", 2:"b", 2:"c"} # BAD: The `2` key is duplicated.
2+
print(dictionary[2])

python/ql/src/Expressions/DuplicateKeyInDictionaryLiteral.qhelp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<qhelp>
55
<overview>
66
<p>Dictionary literals are constructed in the order given in the source.
7-
This means that if a key is duplicated the second key-value pair will overwrite
8-
the first as a dictionary can only have one value per key.
7+
This means that if a key is duplicated, the second key-value pair will overwrite
8+
the first; as a dictionary can only have one value per key.
99
</p>
1010

1111
</overview>
@@ -15,14 +15,14 @@ If they are then decide which value is wanted and delete the other one.</p>
1515

1616
</recommendation>
1717
<example>
18-
<p>This example will output "c" because the mapping between 2 and "b" is overwritten by the
19-
mapping from 2 to "c". The programmer may have meant to map 3 to "c" instead.</p>
18+
<p>The following example will output <code>"c"</code>, because the mapping between 2 and <code>"b"</code> is overwritten by the
19+
mapping from 2 to <code>"c"</code>. The programmer may have meant to map 3 to <code>"c"</code> instead.</p>
2020
<sample src="DuplicateKeyInDictionaryLiteral.py" />
2121

2222
</example>
2323
<references>
2424

25-
<li>Python: <a href="http://docs.python.org/2/reference/expressions.html#dictionary-displays">Dictionary literals</a>.</li>
25+
<li>Python: <a href="http://docs.python.org/3/reference/expressions.html#dictionary-displays">Dictionary literals</a>.</li>
2626

2727
</references>
2828
</qhelp>

python/ql/src/Expressions/ExplicitCallToDel.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ wrap the use of the object in a <code>with</code> statement.
1717

1818
</recommendation>
1919
<example>
20-
<p>In the first example, rather than close the zip file in a conventional manner the programmer has called <code>__del__</code>.
20+
<p>In the first example, rather than close the zip file in a conventional manner, the programmer has called <code>__del__</code>.
2121
A safer alternative is shown in the second example.
2222
</p>
2323

python/ql/src/Expressions/IncorrectComparisonUsingIs.qhelp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ either of the alternatives below.
3737
</example>
3838
<references>
3939

40-
<li>Python Standard Library: <a href="http://docs.python.org/2/library/stdtypes.html#comparisons">Comparisons</a>.</li>
40+
<li>Python Standard Library: <a href="http://docs.python.org/3/library/stdtypes.html#comparisons">Comparisons</a>.</li>
4141

4242
</references>
4343
</qhelp>

python/ql/src/Expressions/IncorrectComparisonUsingIs.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name Comparison using is when operands support `__eq__`
3-
* @description Comparison using 'is' when equivalence is not the same as identity
3+
* @description Comparison using `is` when equivalence is not the same as identity
44
* @kind problem
55
* @tags quality
66
* reliability

python/ql/src/Expressions/UnsupportedFormatCharacter.qhelp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@
33
"qhelp.dtd">
44
<qhelp>
55
<overview>
6-
<p>A format string, that is the string on the left hand side of an expression like <code>fmt % arguments</code>, must consist of legal conversion specifiers.
6+
<p>A printf-style format string (i.e. a string that is used as the left hand side of the <code>%</code> operator, such as <code>fmt % arguments</code>)
7+
must consist of valid conversion specifiers, such as <code>%s</code>, <code>%d</code>, etc.
78
Otherwise, a <code>ValueError</code> will be raised.
89

910
</p>
1011

1112
</overview>
1213
<recommendation>
13-
<p>Choose a legal conversion specifier.</p>
14+
<p>Ensure a valid conversion specifier is used.</p>
1415

1516
</recommendation>
1617
<example>
17-
<p>In <code>format_as_tuple_incorrect</code>, "t" is not a legal conversion specifier.
18+
<p>In the following example, <code>format_as_tuple_incorrect</code>, <code>%t</code> is not a valid conversion specifier.
1819

1920
</p>
2021
<sample src="UnsupportedFormatCharacter.py" />
2122

2223
</example>
2324
<references>
2425

25-
<li>Python Library Reference: <a href="http://docs.python.org/library/stdtypes.html#string-formatting">String Formatting.</a> </li>
26+
<li>Python Library Reference: <a href="https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting">printf-style String Formatting.</a> </li>
2627

2728
</references>
2829
</qhelp>

python/ql/src/Functions/ConsistentReturns.qhelp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<overview>
88
<p>When a function contains both explicit returns (<code>return value</code>) and implicit returns
9-
(where code falls off the end of a function) this often indicates that a return
9+
(where code falls off the end of a function), this often indicates that a return
1010
statement has been forgotten. It is best to return an explicit return value even when returning
1111
<code>None</code> because this makes it easier for other developers to read your code.
1212
</p>
@@ -29,7 +29,7 @@ return value of <code>None</code> as this equates to <code>False</code>. However
2929
</example>
3030
<references>
3131

32-
<li>Python Language Reference: <a href="http://docs.python.org/2/reference/compound_stmts.html#function">Function definitions</a>.
32+
<li>Python Language Reference: <a href="http://docs.python.org/3/reference/compound_stmts.html#function">Function definitions</a>.
3333
</li>
3434

3535

0 commit comments

Comments
 (0)