-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Python: Minor documantation updates to several quality queries #20052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Python: Minor documantation updates to several quality queries #20052
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates documentation for several Python quality queries to reference Python 3 instead of Python 2 documentation links, along with minor grammatical improvements and formatting fixes.
- Updates documentation links from Python 2.7 to Python 3 across multiple query help files
- Fixes grammatical issues by adding missing commas and improving sentence structure
- Updates code formatting to use backticks for consistency and modernizes Python 2 syntax to Python 3
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
ConsistentReturns.expected | Updates error message punctuation (comma addition) |
ModificationOfParameterWithDefault.qhelp | Updates Python documentation link from version 2 to 3 |
InitIsGenerator.qhelp | Updates Python documentation link from version 2.7 to 3 |
ConsistentReturns.ql | Improves code formatting and error message punctuation |
ConsistentReturns.qhelp | Adds missing comma and updates documentation link |
UnsupportedFormatCharacter.qhelp | Clarifies description and updates documentation link |
IncorrectComparisonUsingIs.ql | Updates code formatting for consistency |
IncorrectComparisonUsingIs.qhelp | Updates Python documentation link |
ExplicitCallToDel.qhelp | Adds missing comma for grammatical correctness |
DuplicateKeyInDictionaryLiteral.qhelp | Improves punctuation and updates documentation link |
DuplicateKeyInDictionaryLiteral.py | Modernizes Python 2 syntax to Python 3 and adds explanatory comment |
CallToSuperWrongClass.qhelp | Adds missing commas and updates documentation link |
EmptyExcept.qhelp | Adds missing comma for grammatical correctness |
CatchingBaseException.qhelp | Updates multiple Python documentation links from version 2 to 3 |
QHelp previews: python/ql/src/Exceptions/CatchingBaseException.qhelpExcept block handles 'BaseException'All exception classes in Python derive from Since Catching RecommendationHandle ExampleIn these examples, a function In these examples def call_main_program_implicit_handle_base_exception():
try:
#application.main calls sys.exit() when done.
application.main()
except Exception as ex:
log(ex)
except:
pass
def call_main_program_explicit_handle_base_exception():
try:
#application.main calls sys.exit() when done.
application.main()
except Exception as ex:
log(ex)
except BaseException:
pass
def call_main_program_fixed():
try:
#application.main calls sys.exit() when done.
application.main()
except Exception as ex:
log(ex)
except SystemExit:
pass References
python/ql/src/Exceptions/EmptyExcept.qhelpEmpty exceptIgnoring exceptions that should be dealt with in some way is almost always a bad idea. The loss of information can lead to hard to debug errors and incomplete log files. It is even possible that ignoring an exception can cause a security vulnerability. An empty RecommendationEnsure all exceptions are handled correctly. ExampleIn this example, the program keeps running with the same privileges if it fails to drop to lower privileges. # ...
try:
security_manager.drop_privileges()
except SecurityError:
pass
# ... References
python/ql/src/Expressions/CallToSuperWrongClass.qhelpFirst argument to super() is not enclosing classThe Passing a different class may work correctly, provided the class passed is a super class of the enclosing class and the enclosing class does not define an RecommendationEnsure that the first argument to ExampleIn this example, the call to class Vehicle(object):
pass
class Car(Vehicle):
def __init__(self):
#This is OK provided that Car is not subclassed.
super(Vehicle, self).__init__()
self.car_init()
class StatusSymbol(object):
def __init__(self):
super(StatusSymbol, self).__init__()
self.show_off()
class SportsCar(Car, StatusSymbol):
def __init__(self):
#This will not call StatusSymbol.__init__()
super(SportsCar, self).__init__()
self.sports_car_init()
#Fix Car by passing Car to super().
#SportsCar does not need to be changed.
class Car(Car, Vehicle):
def __init__(self):
super(Car, self).__init__()
self.car_init()
References
python/ql/src/Expressions/DuplicateKeyInDictionaryLiteral.qhelpDuplicate key in dict literalDictionary literals are constructed in the order given in the source. This means that if a key is duplicated, the second key-value pair will overwrite the first; as a dictionary can only have one value per key. RecommendationCheck for typos to ensure that the keys are supposed to be the same. If they are then decide which value is wanted and delete the other one. ExampleThe following example will output dictionary = {1:"a", 2:"b", 2:"c"} # BAD: The `2` key is duplicated.
print(dictionary[2]) References
python/ql/src/Expressions/ExplicitCallToDel.qhelp
|
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Updates documentation of several quality queries, to use python 3 rather than python 2 documentation as references, and a few minor grammatical fixes.