astral-sh / astral-sh/ruff

Possible simplify rule false-negative

Open
#8,633 2 comments 0 reactions 0 assignees View on GitHub
needs-decision rule
Dominant language
Rust
Stars
49.6k
Forks
2.4k
Avg merge
2d 1h
Merged PRs (30d)
458

Description

```python
@cached_property
def python_path(self) -> str:
if self.name == '3.7':
if sys.platform == 'win32':
return r'python\install\python.exe'

return 'python/install/bin/python3'

if sys.platform == 'win32':
return r'python\python.exe'

return 'python/bin/python3'
```

Is that, with everything selected, supposed to be fine? I would have assumed the return would be flagged as the following recommendation:

```python
return r'python\python.exe' if sys.platform == 'win32' else 'python/bin/python3'
```

Feel free to close if this is the expected behavior!

Contributor guide

Open the contributing guide

Research direction

Start with the supplied Python reproducer and run Ruff with all rules selected, then trace the simplify rule that evaluates it. Done means the false-negative behavior is confirmed and the rule either reports the equivalent conditional return or the expected behavior is documented with coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.