Skip to content

[ty] disable division-by-zero by default#18220

Merged
carljm merged 3 commits intomainfrom
cjm/disable-div-zero
May 20, 2025
Merged

[ty] disable division-by-zero by default#18220
carljm merged 3 commits intomainfrom
cjm/disable-div-zero

Conversation

@carljm
Copy link
Contributor

@carljm carljm commented May 20, 2025

Summary

I think division-by-zero is a low-value diagnostic in general; most real division-by-zero errors (especially those that are less obvious to the human eye) will occur on values typed as int, in which case we don't issue the diagnostic anyway. Mypy and pyright do not emit this diagnostic.

Currently the diagnostic is prone to false positives because a) we do not silence it in unreachable code, and b) we do not implement narrowing of literals from inequality checks. We will probably fix (a) regardless, but (b) is low priority apart from division-by-zero.

I think we have many more important things to do and should not allow false positives on a low-value diagnostic to be a distraction. Not opposed to re-enabling this diagnostic in future when we can prioritize reducing its false positives.

References astral-sh/ty#443

Test Plan

Existing tests.

@github-actions
Copy link
Contributor

github-actions bot commented May 20, 2025

mypy_primer results

No ecosystem changes detected ✅

@MichaReiser
Copy link
Member

We should re-enable it for mypy primer here https://github.com/astral-sh/ruff/blob/main/.github/mypy-primer-ty.toml

I'm also not sure if we should disable it. I found the feedback around narrowing limitations useful and we'll miss out on that when it's disabled.

@carljm carljm force-pushed the cjm/disable-div-zero branch from e2198de to 545c7ed Compare May 20, 2025 15:08
@carljm
Copy link
Contributor Author

carljm commented May 20, 2025

I'm also not sure if we should disable it. I found the feedback around narrowing limitations useful and we'll miss out on that when it's disabled.

I feel strongly that we need to improve our focus on the most important issues and avoid (ourselves and our users) being distracted by low-priority issues. If we keep it enabled in the ecosystem, we don't lose this feedback when we choose to make it a priority.

@carljm carljm requested a review from MichaReiser as a code owner May 20, 2025 15:12
@MichaReiser
Copy link
Member

You also need to update the CLI tests. It's used a lot in there because it was one of the first rules that triggered (and it doesn't requier a lot of set up code)

@AlexWaygood AlexWaygood changed the title disable division-by-zero by default [ty] disable division-by-zero by default May 20, 2025
@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label May 20, 2025
@carljm
Copy link
Contributor Author

carljm commented May 20, 2025

You also need to update the CLI tests. It's used a lot in there because it was one of the first rules that triggered (and it doesn't requier a lot of set up code)

Thanks. I was able to update those tests without having to change the code examples -- the same properties of the configuration can be demonstrated by going from "ignored" to "warn" as were previously demonstrated by going from "error" to "warn".

@carljm carljm merged commit d098118 into main May 20, 2025
35 checks passed
@carljm carljm deleted the cjm/disable-div-zero branch May 20, 2025 18:47
@AlexWaygood
Copy link
Member

b) we do not implement narrowing of literals from inequality checks. We will probably fix (a) regardless, but (b) is low priority apart from division-by-zero.

Small correction: we do narrow literals from (in)equality checks, but we don't yet narrow literals from <, <=, > or >= checks: https://play.ty.dev/746ed0da-8731-41f4-b77d-c4cfb8eb7eb2

@carljm
Copy link
Contributor Author

carljm commented May 27, 2025

Yes, that's what I meant. I guess there isn't a simple term for just "greater or less-than checks"!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants