astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.

Home Page:https://docs.astral.sh/ruff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Panic when quoting annotations

thejcannon opened this issue · comments

Version: 0.4.4
Command: ruff check --fix --unsafe-fixes foo.py

I whittled my repro down to:

from .t import RO, RP
from .urs import UR


class MUR(UR):
    def cr(self) -> RO | list[RP]:
        pass

My config is:

[lint]
select = ["TCH"]

[lint.flake8-type-checking]
quote-annotations = true

Stack is:

panicked at /Users/runner/work/ruff/ruff/crates/ruff_text_size/src/range.rs:48:9:
assertion failed: start.raw <= end.raw
Backtrace:    0: std::backtrace::Backtrace::force_capture
   1: <ruff::panic::PanicError as core::fmt::Display>::fmt
   2: std::panicking::rust_panic_with_hook
   3: <std::panicking::begin_panic_handler::StaticStrPayload as core::panic::PanicPayload>::take_box
   4: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   5: _rust_begin_unwind
   6: core::panicking::panic_fmt
   7: core::panicking::panic
   8: ruff_linter::rules::tryceratops::rules::verbose_raise::<impl core::convert::From<ruff_linter::rules::tryceratops::rules::verbose_raise::VerboseRaise> for ruff_diagnostics::diagnostic::DiagnosticKind>::from
   9: ruff_linter::linter::lint_fix
  10: <ruff::diagnostics::FixMap as core::ops::arith::AddAssign>::add_assign
  11: ruff::resolve::resolve
  12: <ruff::panic::PanicError as core::fmt::Display>::fmt
  13: <ruff::cache::PackageCacheMap as ruff::cache::PackageCaches>::get
  14: <ruff::args::LogLevelArgs as clap_builder::derive::Args>::augment_args
  15: <ruff::diagnostics::FixMap as core::ops::arith::AddAssign>::add_assign
  16: <ruff::cache::PackageCacheMap as ruff::cache::PackageCaches>::get
  17: ruff::check
  18: ruff::run
  19: <ruff::cache::PackageCacheMap as ruff::cache::PackageCaches>::get
  20: _main
  21: _main
  22: std::rt::lang_start_internal
  23: _main

I can't seem to reproduce this on v0.4.4 🤔

I'm on 0.4.3, let me try 0.4.4
(Meant to put that in my OP)

Yup! Works in 0.4.4. Nothing in the changelog sticks out to me, but oh well.

Whoops, spoke to soon. Got it on 0.4.4, I forgot to include CLI command.

ruff check --fix --unsafe-fixes

Yup, can reproduce now:

error: Panicked while linting foo.py: This indicates a bug in Ruff. If you could open an issue at:

    https://github.com/astral-sh/ruff/issues/new?title=%5BLinter%20panic%5D

...with the relevant file contents, the `pyproject.toml` settings, and the following stack trace, we'd be very appreciative!

panicked at /Users/runner/work/ruff/ruff/crates/ruff_text_size/src/range.rs:48:9:
assertion failed: start.raw <= end.raw
Backtrace:    0: std::backtrace::Backtrace::force_capture
   1: <ruff::panic::PanicError as core::fmt::Display>::fmt
   2: std::panicking::rust_panic_with_hook
   3: <std::panicking::begin_panic_handler::StaticStrPayload as core::panic::PanicPayload>::take_box
   4: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   5: _rust_begin_unwind
   6: core::panicking::panic_fmt
   7: core::panicking::panic
   8: ruff_linter::rules::tryceratops::rules::verbose_raise::<impl core::convert::From<ruff_linter::rules::tryceratops::rules::verbose_raise::VerboseRaise> for ruff_diagnostics::diagnostic::DiagnosticKind>::from
   9: ruff_linter::linter::lint_fix
  10: <ruff::diagnostics::FixMap as core::ops::arith::AddAssign>::add_assign
  11: ruff::resolve::resolve
  12: <ruff::panic::PanicError as core::fmt::Display>::fmt
  13: <ruff::cache::PackageCacheMap as ruff::cache::PackageCaches>::get
  14: <ruff::args::LogLevelArgs as clap_builder::derive::Args>::augment_args
  15: <ruff::diagnostics::FixMap as core::ops::arith::AddAssign>::add_assign
  16: <ruff::cache::PackageCacheMap as ruff::cache::PackageCaches>::get
  17: ruff::check
  18: ruff::run
  19: <ruff::cache::PackageCacheMap as ruff::cache::PackageCaches>::get
  20: _main
  21: _main
  22: std::rt::lang_start_internal
  23: _main


All checks passed!

I see the issue.