You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FURB152 tries to replace hard-coded constants with the built-in constants (e.g. 3.1415 to math.pi). Unfortunately -- I have found it to be too false-positive happy -- e.g. it will correct 3.15 to math.pi.
There was some discussion about safety at #8727 (comment) and we're a bit divided on it. I'd prefer to leave it as safe for now and instead reduce the false positives. Unsafe isn't really intended to account for false positives i.e. if the rule was always applied correctly would it be safe? It's true that it changes the precision slightly but I don't think it should effect the intent of the code. If we still get feedback that it's causing problems, we can consider changing it.
I agree 3.15 should definitely not change to math.pi. I'd welcome a pull request resolving that issue (and similar).
FURB152 tries to replace hard-coded constants with the built-in constants (e.g.
3.1415
tomath.pi
). Unfortunately -- I have found it to be too false-positive happy -- e.g. it will correct3.15
tomath.pi
.At the very least, I'd argue that this should be an unsafe fix if the constant does not exactly match the builtin (since we will observe some behavioral difference). But I think we should also increase the precision required (e.g. https://github.com/astral-sh/ruff/blob/6bbabceead840e0d232950a1ed1e8f02cdafb92c/crates/ruff_linter/src/rules/refurb/rules/math_constant.rs#L61C29-L61C29) -- I don't have a strong opinion about how precise it should be, but IMO
3.15
should not be corrected tomath.pi
(maybe do it based on the # of digits vs the rounded version?).Would be happy to contribute a patch if you think this a good idea.
The text was updated successfully, but these errors were encountered: