Skip to content

Notebooks: Inconsistent diagnostics between cached/uncached runs #6671

@MichaReiser

Description

@MichaReiser

Input

Notebook:

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "import math"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Some explanation\n",
    "\n",
    "See below"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    print()\n",
    "except ValueError:\n",
    "    pass"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "import pprint\n",
    "\n",
    "random.randint(10, 20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "foo = 1\n",
    "if foo is 2:\n",
    "    raise ValueError(f\"Invalid foo: {foo is 1}\")"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}

Actual Behavior

No cache

 cargo run --bin ruff -- check ../test/test-notebook.ipynb --no-cache
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/ruff check ../test/test-notebook.ipynb --no-cache`
/home/micha/astral/test/test-notebook.ipynb:cell 1:2:8: F401 [*] `math` imported but unused
/home/micha/astral/test/test-notebook.ipynb:cell 5:1:8: F811 Redefinition of unused `random` from line 1
/home/micha/astral/test/test-notebook.ipynb:cell 5:2:8: F401 [*] `pprint` imported but unused
/home/micha/astral/test/test-notebook.ipynb:cell 7:2:4: F632 [*] Use `==` to compare constant literals
/home/micha/astral/test/test-notebook.ipynb:cell 7:3:38: F632 [*] Use `==` to compare constant literals
Found 5 errors.
[*] 4 potentially fixable with the --fix option.

Cached

cargo run --bin ruff -- check ../test/test-notebook.ipynb 
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s
     Running `target/debug/ruff check ../test/test-notebook.ipynb`
warning: Detected debug build without --no-cache.
/home/micha/astral/test/test-notebook.ipynb:2:8: F401 [*] `math` imported but unused
/home/micha/astral/test/test-notebook.ipynb:7:8: F811 Redefinition of unused `random` from line 1
/home/micha/astral/test/test-notebook.ipynb:8:8: F401 [*] `pprint` imported but unused
/home/micha/astral/test/test-notebook.ipynb:13:4: F632 [*] Use `==` to compare constant literals
/home/micha/astral/test/test-notebook.ipynb:14:38: F632 [*] Use `==` to compare constant literals
Found 5 errors.
[*] 4 potentially fixable with the --fix option.

Notice how the uncached uses cell: positions whereas the cached run uses row/colum only.

Expected Behavior

The output between cached and uncached runs is identical.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions