You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- extends type checking and linting to cover also tests
- corrects and complements typing in tests
- handled BUGS DISCOVERED AND THEIR EXPLOITABILITY STATUS in test_util_bug_hunt.py as follows
- 1. right_to_left: Case-sensitive locale checking - system could provide "AR" vs "ar"
locale strings in Artisan are always lowercase, but a .lower() makes the function more robust
- 2. stringtoseconds: Crashes with IndexError on malformed input (some direct calls exist)
the inconsistent handling of malformed input (exception vs returning -1) was consolidated to always raise an exception
- 3. weightVolumeDigits: Incorrect handling of negative values (doesn't use abs())
abs() added
- 4. convertWeight: Accepts negative indices due to Python's negative indexing
modified convertWeight and convertVolume to raise IndexError if any of the two indices is out of range
- 5. is_proper_temp: Accepts infinity values as "proper" temperatures
marked float('-inf') and float('inf') as non-proper temperature values
- 6. decs2string/uchr: No input validation for byte range/Unicode range
a) dec2string: only one call of decs2string in whole code base where the byte range is guaranteed by design
put function as local function there and added an (unnecessary) try-catch for ValueErrors and removed all test cases involving decs2string
b) uchr: added try-catch for ValueErrors returning the empty string for values out of range as suggested
- 7. str2cmd: Crashes on non-ASCII characters
function updated to ignore non-ASCII characters in conversion adding documentation to make clear that Unicode characters are not supported as this is to be used for low-level inter-device communication
- 8 abbrevString: Zero/negative length - length always hardcoded to positive values
semantic of the ll parameter change to give the length of the resulting string with minimum length 1. The last character is always the ellipse character if characters from the original string needed to be dropped to achieve this length
- 9 float2float: Negative precision - precision always hardcoded or from positive functions
documented that precision needs to be >0 and added an abs
- 10 test_toBool_should_handle_eval_injection
commented as this is an known issue we trade for additional functionality
- 11 toInt: Very large floats become huge integers - Python supports arbitrary precision
float('inf') and float('-inf) cannot be converted to int and thus are mapped to 0
corresponding documentation is added
- 12. decodeLocal
hardened the implementation of
decodeLocal/decodeLocalStrict/encodeLocal/encodeLocalStrict
to handle case as the DeprecationWarning may be turned into an exception in future Python versions
------- no explicit numbered issues:
- self.mode => Literal['C','F'] and removes convertRoRstrict test as this is now covered by type checking
- added missing assertions to
test_comma2dot_should_handle_multiple_dots_and_commas
test_comma2dot_should_handle_only_separators
Copy file name to clipboardExpand all lines: src/artisanlib/canvas.py
+5-2Lines changed: 5 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@
40
40
import psutil
41
41
from psutil._common import bytes2human # pyright:ignore[reportPrivateImportUsage]
42
42
43
-
from typing import Final, Optional, List, Set, Dict, Callable, Tuple, Union, Any, Sequence, cast, TYPE_CHECKING #for Python >= 3.9: can remove 'List' since type hints can now use the generic 'list'
43
+
from typing import Final, Optional, Literal, List, Set, Dict, Callable, Tuple, Union, Any, Sequence, cast, TYPE_CHECKING #for Python >= 3.9: can remove 'List' since type hints can now use the generic 'list'
44
44
45
45
if TYPE_CHECKING:
46
46
from artisanlib.comm import serialport # pylint: disable=unused-import
0 commit comments