Skip to content
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

"Expression value is unused" should not be reported for last expression in notebook cell #3282

Closed
matangover opened this issue Sep 4, 2022 · 6 comments
Assignees
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version notebooks

Comments

@matangover
Copy link

Jupyter notebook uses the last expression in each cell as the cell's output. Hence, it should not be reported as unused.

@judej judej added the needs investigation Could be an issue - needs investigation label Sep 6, 2022
@debonte debonte self-assigned this Sep 6, 2022
@debonte debonte added notebooks bug Something isn't working and removed needs investigation Could be an issue - needs investigation labels Sep 6, 2022
@debonte debonte added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Nov 11, 2022
@rchiodo rchiodo closed this as completed Nov 17, 2022
@rchiodo
Copy link
Contributor

rchiodo commented Nov 17, 2022

This issue has been fixed in prerelease version 2022.11.31, which we've just released. You can find the changelog here: CHANGELOG.md

@alecglen
Copy link

alecglen commented Dec 1, 2022

I am still seeing this behavior in v2022.11.40 and v2022.11.41 (pre-release).

@rchiodo
Copy link
Contributor

rchiodo commented Dec 1, 2022

What's your version of the jupyter extension? It may be providing its own errors in this situation if it's not the latest prerelease for jupyter too. (I ran into this problem too)

@dream-dasher
Copy link

Hi there.
Is there a way to get this behavior in notebook files saved as .py.

A generally preferable (opinion) way of working with notebooks is as raw code -- using something like Jupytext or Zed's Repl environ, both of which allow using comments to demarcate cells. (This allows for tool interoperation between python code and note books, useable git diffs, notebooks to be run as scripts, etc.)

e.g. :

# %%
preproced = "Hello, {{name}}, {{name}},  }}."
procd = replace_placeholder(preproced, "name", "__Alice__")
procd

# %%
procd_counted = extract_placeholders(procd)
len(procd_counted)

Pyright, of course, doesn't recognize the comment syntax. Is there a way to give it a specific file or director over which the "unused expression" can be ignored?

@rchiodo
Copy link
Contributor

rchiodo commented Jan 21, 2025

Sorry there's no way to specify that a #%% commented file is actually a set of cells, but sounds like a good enhancement request. VS code has had an interactive window that supports #%% for a long time and it seems like we should treat those files differently.

@debonte
Copy link
Contributor

debonte commented Jan 21, 2025

sounds like a good enhancement request

These existing enhancement requests might cover the functionality that you are hoping to see. If so, please up-vote them:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version notebooks
Projects
None yet
Development

No branches or pull requests

6 participants