Deprecated slice method¶
ID: py/deprecated-slice-methodKind: problemSecurity severity: Severity: warningPrecision: very-highTags: - maintainabilityQuery suites: - python-security-and-quality.qls
Click to see the query in the CodeQL repository
The__getslice__,__setslice__ and__delslice__ methods have been deprecated since Python 2.0. In general, no class should implement these methods.
The only exceptions to this rule are classes that inherit fromlist and override__getitem__,__setitem__ or__delitem__. Sincelist implements the slicing methods any class inheriting fromlist must implement the the slicing methods to ensure correct behavior of__getitem__,__setitem__ and__delitem__. These exceptions to the rule will not be treated as violations.
Recommendation¶
Delete the slicing method. Any functionality should be moved to the equivalent__xxxitem__ method:
__getslice__should be replaced with__getitem____setslice__should be replaced with__setitem____delslice__should be replaced with__delitem__
References¶
Python Language Reference: Additional methods for emulation of sequence types.