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

Removal of semicolon in notebooks #7300

Closed
peendebak opened this issue Sep 12, 2023 · 7 comments
Closed

Removal of semicolon in notebooks #7300

peendebak opened this issue Sep 12, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@peendebak
Copy link

One of the default rules in ruff is to remove a trailing semicolon. That is fine for python scripts, for for jupyter notebook this can change the output of the code cells. A screenshot to illustrate:

image

The removal of the semicolon results in the output of the plt.plot command being displayed. Typically this is not the intention, so a semicolor is used to hide the command output and only the the plotted graph.

Can the ruff default settings be modified to remove semicolons for python files, but not for notebooks?

@dhruvmanila
Copy link
Member

I think this might be similar to #6586 where it's only the last expression in a cell where this rule should be disabled. We could probably have a general interface internally to include rules which need not be checked for last expressions in all cells within a Jupyter Notebook.

Until that is supported, you could disable this rule on Jupyter Notebooks like so:

[tool.ruff]
per-file-ignores = { "*.ipynb" = ["E703"] }

https://beta.ruff.rs/docs/rules/useless-semicolon/

@henryiii
Copy link
Contributor

There are several rules that don't apply to notebooks, or apply in a modified form. B018 - A useless expression at the end of a cell is actually not useless, that's how you show the (notebook customized if applicable) display of an object. T20 also usually doesn't apply, notebooks are not library files, but I think it's fine to have to disable that.

Ideally B018 and E703 would learn that when in a cell, they don't apply to the last item in the cell.

@charliermarsh
Copy link
Member

Agreed.

@charliermarsh
Copy link
Member

We already had to solve this cell-boundaries problem for isort, so should be doable in these cases too.

@s-weigand
Copy link

s-weigand commented Nov 8, 2023

[tool.ruff]
per-file-ignores = { "*.ipynb" = ["E703"] }

Sadly this seems not to be respected by ruff format 😢
Even so, it is not part of the conflicting rules

@dhruvmanila
Copy link
Member

(Merging this with a general tracking issue: #8669)

@dhruvmanila dhruvmanila closed this as not planned Won't fix, can't repro, duplicate, stale Nov 14, 2023
@dhruvmanila
Copy link
Member

[tool.ruff]
per-file-ignores = { "*.ipynb" = ["E703"] }

Sadly this seems not to be respected by ruff format 😢 Even so, it is not part of the conflicting rules

@s-weigand Hi, we recently updated the formatter to not remove any trailing semicolon in notebook context: #8590. It'll be available in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants