-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Notebook related rule updates #8669
Comments
I think another rule that makes less sense in notebooks is |
Thanks for chiming in on the issue! Can you help me understand when does For |
Yes, I would put everything I write in a module in the module docstring in a notebook in a markdown cell, which is why it makes no sense to have a module docstring.
That's what I basically wanted to say. That it makes no sense to me in notebooks that the rule triggers. |
## Summary This PR updates the `E703` rule to avoid flagging any semicolons if they're present after the last expression in a notebook cell. These are intended to hide the cell output. Part of #8669 ## Test Plan Add test notebook and update the snapshots.
I'm a bit torn on how to go for
I'm thinking of going with (3) in preview. |
## Summary This PR updates the `E402` rule to work at cell level for Jupyter notebooks. This is enabled only in preview to gather feedback. The implementation basically resets the import boundary flag on the semantic model when we encounter the first statement in a cell. Another potential solution is to introduce `E403` rule that is specifically for notebooks that works at cell level while `E402` will be disabled for notebooks. ## Test Plan Add a notebook with imports in multiple cells and verify that the rule works as expected. resolves: #8669
Thanks for maintaining this great project!
In some of our projects, we work with notebooks where we prefer to put all imports in one cell at the top of the notebook. If I understand correctly, there is no rule anymore that can enforce this. Might it be an idea to define a new rule If this idea is worth pursuing, I can post it as a separate issue. |
@redeboer Yeah, I think we can discuss this in a separate issue. |
This is an open discussion around linting Jupyter Notebooks using certain rules that doesn't map well with the notebook model.
For some context, Notebooks are made up of cells, each cell can be assumed to act as a single Python file but that's not exactly true as anything defined in a cell is available throughout the notebook via the global scope.
There are certain lint rules which doesn't map well with notebooks and this issue is to keep track of them in a central place. We can discuss on possible solutions here.
E402: module-import-not-at-top-of-file
- Usually imports definition in a notebook is scattered across multiple cells. The current workaround is to ignore this rule but one could argue that this rule should work at cell level i.e., "Module level import not at top of cell".B018: useless-expression
,B015: useless-comparison
- Expressions in a cell are not useless if they're at the end because the result of that expression is the output of the cell. So, these rules should be updated to avoid raising any violation if it's the last expression in the cell.E703: useless-semicolon
- On the other hand, semicolons are used to avoid the output mentioned in the previous point. If there's a trailing semicolon for the last expression in a cell, it's probably best to avoid raising a violation for it. The formatter does a similar thing: Preserve trailing semicolon for Notebooks #8590D100: undocumented-public-module
- This is irrelevant for Notebooks.The text was updated successfully, but these errors were encountered: