EDIT: I am wrong, `ty` can catch this, but the associated rule is considered less-than-reliable by the maintainers. See replies!

gave `ty check` a try out of curiosity to see if it could do a better job with my biggest `ruff check` bug-bear: catching undefined names caused by uncareful branching logic ("happy path" programming)

it does catch the flaw with trivial predicates (`if False:`) but it appears that programs with this kind of branching flaw will sail through as false positives, the same as `ruff check`

```python
import random

y = -1

if random.random() < 0.5:
x = 42
# else x undefined

print(x, y)
```

This flaw in `ruff` was reported in 2024, and while there were a few false-starts on trying to resolve it, it remains unresolved, in part because the control flow analysis necessary was being worked on for what became `ty` and I guess cannot be shared between the two tools.

github.com/astral-sh/ruff/issu

This isn't the only thing that's kept me away from *relying* on `ruff` (or now, `ty`), but I consider it a useful canary issue because it comes up a LOT and the tools I am used to using are able to handle it. If Astral's tools catch up to that level of functionality, the speed-up is very attractive, but I'm not willing to sacrifice the one for the other.

0

If you have a fediverse account, you can quote this note from your own instance. Search https://hachyderm.io/users/SnoopJ/statuses/115737928203655742 on your instance and quote it. (Note that quoting is not supported in Mastodon.)