Multiple instances of Python object-testing mistakes
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
HPLIP |
New
|
Undecided
|
Unassigned |
Bug Description
The HPLIP Python code contains multiple instances where a string literal is compared with a variable using identity comparison ("is" / "is not"), which as the language reference will tell you (and a warning output to the terminal notes) is generally ill-advised.
IOW, taking an example from ui5/devmgr5.py:
if self.latest_
The way to write such a comparison without triggering a SyntaxWarning is,
if self.latest_
"is not" and "is" should generally only be used to check whether two variables refer to the _exact same object_ or literal. The most common uses are "somevar is None" or "somevar is not None". None is a singleton object, so there can only ever be one instance of None in the runtime.
Additionally, base/pexpect/
if timeout < 0 and timeout is not None:
if timeout ever actually is None, attempting to compare it to an integer will trigger an exception, "TypeError: '<' not supported between instances of 'NoneType' and 'int'". To properly short-circuit the evaluation, the order of the two tests must be reversed.
The attached patch contains fixes for the pexpect condition, and replaces all instances of "is not <string literal>" that I could find with "!= <string literal>". I can't guarantee there aren't still others lurking in the code somewhere, though.
summary: |
- Multiple instances of Python object-testing errors + Multiple instances of Python object-testing mistakes |
description: | updated |
(Wow! 2 millionth bug. I feel like there should be balloons or something.)