-
Notifications
You must be signed in to change notification settings - Fork 766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Final annotation is not recognized across notebook cells #6455
Comments
Is it not works for jupyter notebook? I had set to |
It does work for me in the untitled case too though. Must be the typecheckingmode is not being applied for some reason to your notebook. |
Not work. I had tried both untitled or saved file. |
Can you include your logs after running 'Pylance : Start Logging'. It should tell us which workspace we think the notebook is in. |
Hope these helpful. 1.mp4 |
Hmm, I can reproduce it now too using workspace settings.json. Not sure why that matters. |
Yeah there's an error reading the settings for some reason. Here:
|
Figured out the problem internally. We're not propagating the imports from the first cell to the second cell. If you put the import in the same cell, the error shows up:
|
I can reproduce this with two python files (no need for a notebook). Should be a pyright issue? Create two files: exporting_file.py: from typing import Final importing_file.py from exporting_file import *
x: Final[int] = 1
x = 2 # should be an error here and there isn't This is basically the internal structure of how notebook cells are linked together. |
@rchiodo, you can't re-export In most languages, |
Hmm, that means in a notebook they have to be in the same cell then as our workaround for cells referencing each other doesn't work in this case. |
Transferring back to Pylance. We might have to special case this for notebooks then. |
@erictraut is it only TypeAliases that can't be reexported? Or might there be other cases? I mean functions and variables obviously work and normal imports as well. Like this is fine: # Exporting_file.py
import pytest as py # Importing_file.py
from exporting_file import *
py.foo() |
It's only the How is pylance currently making symbols from one cell visible to subsequent cells? Are you synthesizing a wildcard import statement for pyright, like you show in the above sample? |
Sort of? The binder binds them as implicit imports, but I'm having trouble finding how that affects the import resolver. Meaning how they are actually considered. Maybe we can tweak something in the import resolver for this special case. |
Oh it's the binding that's linking everything together. It's not the same as a wildcard import. It specifies the previous cell as the list of builtins. This makes all of the symbols in the previous cell count as builtin symbols for the next cell. |
OK, got it. I have some ideas for how to fix this, but they're going to require some explorations. I'll get back to you. |
I've had a chance to explore some options. The underlying issue here is that the binder needs to make some assumptions about I explored a couple of options:
Option 2 is more surgical, so I went with that solution. This will be included in the next release of pyright. @rchiodo, when you pull the code from pyright, please verify that it works with pylance's notebook support. You may want to add a pylance test case specifically for this. |
Thanks a lot. Will do. |
Environment data
v2024.9.2
Win11 23H2
Conda Python 3.11.9
Code Snippet
Repro Steps
Expected behavior
Show me some warning like: "you can't change constant".
Actual behavior
No warning.
Logs
The text was updated successfully, but these errors were encountered: