ruff
b9139a31 - [`flake8-pie`] Omit bound tuples passed to `.startswith` or `.endswith` (#9661)

Commit
1 year ago
[`flake8-pie`] Omit bound tuples passed to `.startswith` or `.endswith` (#9661) ## Summary This review contains a fix for [PIE810](https://docs.astral.sh/ruff/rules/multiple-starts-ends-with/) (multiple-starts-ends-with) The problem is that ruff suggests combining multiple startswith/endswith calls into a single call even though there might be a call with tuple of strs. This leads to calling startswith/endswith with tuple of tuple of strs which is incorrect and violates startswith/endswith conctract and results in runtime failure. However the following will be valid and fixed correctly => ```python x = ("hello", "world") y = "h" z = "w" msg = "hello world" if msg.startswith(x) or msg.startswith(y) or msg.startswith(z) : sys.exit(1) ``` ``` ruff --fix --select PIE810 --unsafe-fixes ``` => ```python if msg.startswith(x) or msg.startswith((y,z)): sys.exit(1) ``` See: https://github.com/astral-sh/ruff/issues/8906 ## Test Plan ```bash cargo test ```
Author
Parents
Loading