Skip to content

[pyupgrade] Fix panic caused by handling of octals in UP012#24390

Merged
dylwil3 merged 3 commits intoastral-sh:mainfrom
dylwil3:up012-crash
Apr 3, 2026
Merged

[pyupgrade] Fix panic caused by handling of octals in UP012#24390
dylwil3 merged 3 commits intoastral-sh:mainfrom
dylwil3:up012-crash

Conversation

@dylwil3
Copy link
Copy Markdown
Collaborator

@dylwil3 dylwil3 commented Apr 3, 2026

This fixes two errors introduced by #16058 :

  • An off-by-one error caused a panic when UP012 was run on strings ending in an octal (and could also cause the rule to trigger when it should not, e.g. for "\000\N{DIGIT ONE}").
  • When checking that an octal \abc was not larger than \377, it was parsed using "abc".parse::<u8>(). But this uses base 10. We need to use u8::from_str_radix("abc",8) instead.

Closes #24389

@dylwil3 dylwil3 added bug Something isn't working rule Implementing or modifying a lint rule labels Apr 3, 2026
@astral-sh-bot astral-sh-bot bot requested a review from ntBre April 3, 2026 09:45
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Apr 3, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dylwil3 dylwil3 removed the request for review from ntBre April 3, 2026 13:26
@dylwil3 dylwil3 enabled auto-merge (squash) April 3, 2026 13:30
@dylwil3 dylwil3 merged commit 23364ae into astral-sh:main Apr 3, 2026
42 checks passed
@dylwil3 dylwil3 deleted the up012-crash branch April 3, 2026 13:34
carljm added a commit that referenced this pull request Apr 3, 2026
* main:
  Document adding fixes in CONTRIBUTING.md (#24393)
  Sort formatter diagnostics in snapshots (#24375)
  [`pyupgrade`] Fix panic caused by handling of octals in `UP012` (#24390)
  Upgrade to nix v0.31.2 (#24385)
  Strip form feeds from indent passed to `dedent_to` (#24381)
  add recent move of the `deferred` submodule to `.git-blame-ignore-revs` (#24379)
  [ty] Fix extra_items TypedDict tests (#24367)
  [ty] Use `infer_type_expression` for validating PEP-613 type aliases (#24370)
  [`flake8-simplify`] Make the fix for `collapsible-if` (`SIM102`) safe in `preview` (#24371)
  [ty] Validate TypedDict fields when subclassing (#24338)
  [ty] pass type context to sequence literals in binary operations (#24197)
  Add release environment to notify-dependents job (#24372)
  Bump 0.15.9 (#24369)
  [ty] Move the `deferred` submodule inside `infer/builder` (#24368)
  [ty] Infer the `extra_items` keyword argument to class-based TypedDicts as an annotation expression (#24362)
  [ty] Validate type qualifiers in functional TypedDict fields and the `extra_items` keyword to functional TypedDicts (#24360)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

String ending with octal causes panic when UP012 selected

2 participants