Skip to content

fix(nblint): check Python syntax in timed cells - #1434

Merged
Giom-V merged 4 commits into
google-gemini:mainfrom
BichengWang:fix-nblint-timed-cells
Nov 2, 2026
Merged

Giom-V merged 4 commits into
google-gemini:mainfrom
BichengWang:fix-nblint-timed-cells

Conversation

@BichengWang

Copy link
Copy Markdown
Contributor

nblint skips every cell starting with %%, so %%time\nbroken = passes the syntax check even though its Python body cannot compile. There are 22 %%time cells in the current notebooks.

Check %%time bodies using the existing IPython syntax normalization, which preserves the original cell line numbers. Keep other cell magics skipped because their bodies may contain non-Python content. Add offline regression tests and update the rule documentation.

Validation:

  • python3 -m unittest tools.test_nblint_syntax tools.test_check_all_links -v — 25 tests pass; the new regressions fail on the original implementation.
  • Full nblint_cli.py run over 154 notebooks — zero failures.
  • All 22 existing timed cells pass syntax checks and reject an appended broken = in memory.
  • python3 tools/check_all_links.py tools/README.md and git diff --check pass.

No notebooks were executed or changed.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the robustness of the notebook linting process by ensuring that Python code inside %%time cells is subject to the same syntax validation as standard code cells. By explicitly including %%time while continuing to ignore other non-Python cell magics, the tool now catches potential syntax errors that were previously missed, without introducing false positives for non-Python cell types.

Highlights

  • Enhanced Syntax Checking: Updated the nblint tool to include %%time cells in Python syntax validation, ensuring that code within these timed cells is correctly parsed and checked for errors.
  • Regression Testing: Added a new test suite, tools/test_nblint_syntax.py, to verify that timed cells are correctly validated while other cell magics remain appropriately skipped.
  • Documentation Update: Updated the lint rules reference in tools/README.md to reflect the change in how %%time cells are handled during syntax checks.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@github-actions github-actions Bot added the status:awaiting review PR awaiting review from a maintainer label Oct 17, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the notebook linter (nblint) to parse and validate the syntax of Python code cells that use the %%time cell magic, while continuing to skip other non-Python cell magics. It also introduces a comprehensive test suite in tools/test_nblint_syntax.py to verify this behavior. The feedback suggests optimizing the check for %%time by using src.split(maxsplit=1)[0] instead of src.split()[0] to avoid splitting the entire content of large notebook cells, which improves performance.

Comment thread tools/nblint/rules/syntax.py Resolved
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@kkorpal kkorpal self-assigned this Oct 19, 2026
@kkorpal

kkorpal commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Thanks, nice catch. Verified locally: 25/25 tests pass, the new tests fail against the current syntax.py, all 22 %%time cells in the repo pass as-is and each one is flagged if I append broken =, and a full nblint run over all notebooks is unchanged (0 failures, same warnings as main). LGTM.

Same note as on #1432: tools/test_nblint_syntax.py isn't run by CI yet leaving that to @Giom-V.

@BichengWang

Copy link
Copy Markdown
Contributor Author

Added the syntax tests to the notebook workflow and enabled it for tool and workflow changes. All 25 syntax and link-checker tests pass locally.

@BichengWang

Copy link
Copy Markdown
Contributor Author

@Giom-V, the syntax tests now run in CI and all checks are green. Does the CI wiring look good to you?

@Giom-V Giom-V left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @BichengWang! I removed the unit tests and CI step from this PR so we don't have to maintain a separate unit test suite for internal helper scripts. Merging!

@Giom-V
Giom-V merged commit 21372e2 into google-gemini:main Nov 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:awaiting review PR awaiting review from a maintainer type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants