ruff/crates
Dan Parizher 47e41ac6b6
[refurb] Fix false negative for underscores before sign in Decimal constructor (FURB157) (#21190)
## Summary

Fixes FURB157 false negative where `Decimal("_-1")` was not flagged as
verbose when underscores precede the sign character. This fixes #21186.

## Problem Analysis

The `verbose-decimal-constructor` (FURB157) rule failed to detect
verbose `Decimal` constructors when the sign character (`+` or `-`) was
preceded by underscores. For example, `Decimal("_-1")` was not flagged,
even though it can be simplified to `Decimal(-1)`.

The bug occurred because the rule checked for the sign character at the
start of the string before stripping leading underscores. According to
Python's `Decimal` parser behavior (as documented in CPython's
`_pydecimal.py`), underscores are removed before parsing the sign. The
rule's logic didn't match this behavior, causing a false negative for
cases like `"_-1"` where the underscore came before the sign.

This was a regression introduced in version 0.14.3, as these cases were
correctly flagged in version 0.14.2.

## Approach

The fix updates the sign extraction logic to:
1. Strip leading underscores first (matching Python's Decimal parser
behavior)
2. Extract the sign from the underscore-stripped string
3. Preserve the string after the sign for normalization purposes

This ensures that cases like `Decimal("_-1")`, `Decimal("_+1")`, and
`Decimal("_-1_000")` are correctly detected and flagged. The
normalization logic was also updated to use the string after the sign
(without underscores) to avoid double signs in the replacement output.
2025-11-04 11:02:50 -05:00
..
ruff Update Rust toolchain to 1.91 (#21179) 2025-11-01 01:50:58 +00:00
ruff_annotate_snippets Display diffs for ruff format --check and add support for different output formats (#20443) 2025-09-30 12:00:51 -04:00
ruff_benchmark [ty] Update expected diagnostic count in benchmarks (#21269) 2025-11-04 03:18:12 +00:00
ruff_cache
ruff_db [ty] Smaller refactors to server API in prep for notebook support (#21095) 2025-10-31 20:00:04 +00:00
ruff_dev Update Rust toolchain to 1.91 (#21179) 2025-11-01 01:50:58 +00:00
ruff_diagnostics
ruff_formatter [ty] Use "cannot" consistently over "can not" (#21255) 2025-11-03 10:38:20 -05:00
ruff_graph [ruff]: Make ruff analyze graph work with jupyter notebooks (#21161) 2025-10-31 21:47:01 +00:00
ruff_index
ruff_linter [refurb] Fix false negative for underscores before sign in Decimal constructor (FURB157) (#21190) 2025-11-04 11:02:50 -05:00
ruff_macros Document when a rule was added (#21035) 2025-10-23 14:48:41 -04:00
ruff_memory_usage [ty] Clean up inherited generic contexts (#20647) 2025-10-03 13:55:43 -04:00
ruff_notebook Display diffs for ruff format --check and add support for different output formats (#20443) 2025-09-30 12:00:51 -04:00
ruff_options_metadata
ruff_python_ast [refurb] Preserve argument ordering in autofix (FURB103) (#20790) 2025-10-31 11:16:09 -04:00
ruff_python_ast_integration_tests
ruff_python_codegen Configurable "unparse mode" for ruff_python_codegen::Generator (#21041) 2025-10-24 15:44:48 +00:00
ruff_python_formatter Avoid extra parentheses for long match patterns with as captures (#21176) 2025-11-03 17:06:52 -05:00
ruff_python_importer
ruff_python_index
ruff_python_literal
ruff_python_parser Consistently wrap tokens in parser diagnostics in backticks instead of 'quotes' (#21163) 2025-10-31 11:59:11 -04:00
ruff_python_semantic [pyflakes] Revert to stable behavior if imports for module lie in alternate branches for F401 (#20878) 2025-10-27 10:23:36 -05:00
ruff_python_stdlib [ruff] Extend FA102 with listed PEP 585-compatible APIs (#20659) 2025-10-03 09:45:32 -04:00
ruff_python_trivia Handle t-string prefixes in SimpleTokenizer (#20578) 2025-09-25 14:33:37 -05:00
ruff_python_trivia_integration_tests Handle t-string prefixes in SimpleTokenizer (#20578) 2025-09-25 14:33:37 -05:00
ruff_server Fix missing diagnostics for notebooks (#21156) 2025-10-31 01:16:43 +00:00
ruff_source_file
ruff_text_size [ruff] Update schemars to v1 (#20942) 2025-10-20 08:59:52 +02:00
ruff_wasm Bump v0.14.3 (#21152) 2025-10-30 17:06:29 -07:00
ruff_workspace Improve extend docs (#21135) 2025-10-31 15:10:14 +00:00
ty [ty] don't assume in diagnostic messages that a TypedDict key error is about subscript access (#21166) 2025-10-31 10:49:59 -04:00
ty_combine
ty_completion_eval [ty] Favor in scope completions (#21194) 2025-11-03 09:33:05 -05:00
ty_ide [ty] Simplify semantic token tests (#21206) 2025-11-03 15:35:42 +00:00
ty_project [ty] Simplify semantic token tests (#21206) 2025-11-03 15:35:42 +00:00
ty_python_semantic [ty] Allow values of type None in type expressions (#21263) 2025-11-04 16:29:55 +01:00
ty_server [ty] Remove mentions of VS Code from server logs (#21155) 2025-11-03 14:49:58 +00:00
ty_static [ty] improve base conda distinction from child conda (#20675) 2025-10-03 13:56:06 +00:00
ty_test [ty] Fix bug where ty would think all types had an __mro__ attribute (#20995) 2025-10-27 11:19:12 +00:00
ty_vendored [ty] Sync vendored typeshed stubs (#21178) 2025-10-31 21:03:40 -04:00
ty_wasm [ruff,ty] Enable tracing's log feature 2025-10-03 08:18:03 -04:00