astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
31.13k stars 1.03k forks source link

[Linter panic] ruff 0.0.258: 'internal error: entered unreachable code: Expected docstring to start with a valid triple- or single-quote prefix', crates/ruff_python_ast/src/str.rs:38:5 #3678

Closed XuehaiPan closed 1 year ago

XuehaiPan commented 1 year ago

Ref https://github.com/metaopt/optree/actions/runs/4497862525/jobs/7913866886, the step pre-commit (ruff 0.0.257 runs successfully), while ruff 0.0.258 reports panic.

Create a new isolated virtual environment:

$ git clone --depth=1 https://github.com/metaopt/optree.git
$ cd optree
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install --upgrade ruff
Collecting ruff
  Using cached ruff-0.0.258-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB)
Installing collected packages: ruff
Successfully installed ruff-0.0.258

[notice] A new release of pip available: 22.3.1 -> 23.0.1
[notice] To update, run: pip install --upgrade pip
$ ruff --version             
ruff 0.0.258

The panic is not always reproducible:

$ source venv/bin/activate
$ ruff check optree/typing.py  # OK
$ ruff check optree/typing.py  # OK

$ deactivate
$ source venv/bin/activate
$ ruff check optree/typing.py
warning: Linting panicked optree/typing.py: This indicates a bug in `ruff`. If you could open an issue at:

https://github.com/charliermarsh/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 'internal error: entered unreachable code: Expected docstring to start with a valid triple- or single-quote prefix', crates/ruff_python_ast/src/str.rs:38:5
Backtrace:    0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: <unknown>
   5: <unknown>
   6: <unknown>
   7: <unknown>
   8: <unknown>
   9: <unknown>
  10: <unknown>
  11: <unknown>
  12: <unknown>
  13: <unknown>
  14: <unknown>
  15: <unknown>
  16: <unknown>
  17: <unknown>
  18: __libc_start_main
             at /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:308:16
  19: <unknown>

pyproject.toml: https://github.com/metaopt/optree/blob/828749a91b985cb56fc0888c26939080be4f677d/pyproject.toml#L139-L227 optree/typing.py: https://github.com/metaopt/optree/blob/828749a91b985cb56fc0888c26939080be4f677d/optree/typing.py

All docstrings are valid and start with triple-quotes. No panic was reported for the previous release ruff 0.0.257.

I have

[tool.ruff]
typing-modules = ["optree.typing"]

in my configuration. Not sure if this is the cause here.

charliermarsh commented 1 year ago

Thanks! I'll take a look today.

charliermarsh commented 1 year ago

Reproduced...