mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
![]() Fixes false negative when slice bound uses length of string literal. We were meant to check the following, for example. Given: ```python text[:bound] if text.endswith(suffix) else text ``` We want to know whether: - `suffix` is a string literal and `bound` is a number literal - `suffix` is an expression and `bound` is exactly `-len(suffix)` (as AST nodes, prior to evaluation.) The issue is that negative number literals like `-10` are stored as unary operators applied to a number literal in the AST. So when `suffix` was a string literal but `bound` was `-len(suffix)` we were getting caught in the match arm where `bound` needed to be a number. This is now fixed with a guard. Closes #16231 |
||
---|---|---|
.. | ||
fixtures | ||
package | ||
project | ||
__init__.py | ||
disallowed_rule_names.txt |