basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

symbols defined in other notebook cells are not available when notebook has not been saved to disk

Open rosborn opened this issue 9 months ago • 3 comments

Description

When defining a class in a VSCodium notebook, basedpyright seems to forget about the class in the next code block if the .ipynb file isn't saved to disk. If a new jupyter notebook is created then the following two blocks will create an error.

class Foo:
    def __init__(self, a: int) -> None:
        self.a: int = a


test = Foo(a=1)  # Works
test = Foo(a=1)  # "Foo" is not defined basedpyright reportUndefinedVariable

When you save the file to disk, the error goes away, but basedpyright outputs the following error to VSCodium:

Request textDocument/inlayHint failed.
  Message: Request textDocument/inlayHint failed with message: Cannot read properties of undefined (reading 'key')
  Code: -32603 

This error is reported every time the line of code in the second block is scrolled past or edited.

I am running basedpyright language server 1.29.1 and the following: VSCodium Version: 1.99.32846 Commit: 0d1cad16ae0ec643ad1fd85b4ba8e52dacf42e85 Date: 2025-04-28T14:52:44.169Z Electron: 34.3.3 ElectronBuildId: undefined Chromium: 132.0.6834.210 Node.js: 20.18.3 V8: 13.2.152.41-electron.0 OS: Darwin arm64 24.4.0

Let me know if there's any additional diagnostic information I can provide.

rosborn avatar May 04 '25 17:05 rosborn

i can't reproduce that reportUndefinedVariable error but i do see the inlay hint error

DetachHead avatar May 11 '25 09:05 DetachHead

how are the cells ordered? the cell where the class is defined must be above the cell that uses it, or it will crash at runtime

DetachHead avatar May 11 '25 09:05 DetachHead

ok nvm i reproduced it. i've opened #1279 for the inlay hint crash because it's a separate issue

DetachHead avatar May 11 '25 11:05 DetachHead