Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

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


[8]ページ先頭

©2009-2025 Movatter.jp