[PR #1877] fix(module): syntax errors in student notebook silently pass tito module complete #27338

Open
opened 2026-06-18 16:55:38 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/harvard-edge/cs249r_book/pull/1877
Author: @Shashank-Tripathi-07
Created: 6/16/2026
Status: 🔄 Open

Base: mainHead: fix/module-complete-tests-src-not-notebook


📝 Commits (1)

  • 9b6e253 catch notebook syntax errors before export so they do not silently pass

📊 Changes

1 file changed (+48 additions, -0 deletions)

View changed files

📝 tinytorch/tito/commands/module/workflow.py (+48 -0)

📄 Description

Bug report

Reported by @Chufeng-Jiang in discussion #1827.

A student had a syntax error in their Module 01 notebook (missing closing parenthesis in an isinstance call). Running tito module complete 01 reported all tests passing. The error only surfaced when Module 02 tests tried to import from the broken tinytorch/core/tensor.py that the export had written.

Root cause

_run_inline_unit_tests() runs the instructor's source file at src/01_tensor/01_tensor.py, not the student's notebook at modules/01_tensor/tensor.ipynb. A syntax error in the student's notebook is invisible to this test phase -- the instructor source always runs clean. The broken notebook then gets exported into tinytorch/core/tensor.py without any parse check.

Fix

Add _check_notebook_syntax(): reads the student's notebook, compiles every code cell with Python's compile(), and returns the first SyntaxError found with the cell number and line. Called in both complete_module and _complete_module_quiet immediately before the export step, so the student sees:

❌ Syntax error in your notebook -- fix it before exporting
   SyntaxError in tensor.ipynb cell 12, line 3: '(' was never closed
     if len(shape) == 1 and isinstance(shape[0], (tuple, list):

instead of a confusing failure in the next module.

Test plan

  • Student notebook with a syntax error: tito module complete 01 reports the error with cell + line number and exits 1
  • Valid notebook: behaviour unchanged, export proceeds normally
  • tito module complete --all (quiet path) also blocked on syntax errors

Co-authored-by: Chufeng Jiang cjiang@gradcenter.cuny.edu


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/harvard-edge/cs249r_book/pull/1877 **Author:** [@Shashank-Tripathi-07](https://github.com/Shashank-Tripathi-07) **Created:** 6/16/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/module-complete-tests-src-not-notebook` --- ### 📝 Commits (1) - [`9b6e253`](https://github.com/harvard-edge/cs249r_book/commit/9b6e2538d8bcf6ac80f77b61c8b852439443406c) catch notebook syntax errors before export so they do not silently pass ### 📊 Changes **1 file changed** (+48 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `tinytorch/tito/commands/module/workflow.py` (+48 -0) </details> ### 📄 Description ## Bug report Reported by @Chufeng-Jiang in discussion #1827. A student had a syntax error in their Module 01 notebook (missing closing parenthesis in an `isinstance` call). Running `tito module complete 01` reported all tests passing. The error only surfaced when Module 02 tests tried to import from the broken `tinytorch/core/tensor.py` that the export had written. ## Root cause `_run_inline_unit_tests()` runs the instructor's source file at `src/01_tensor/01_tensor.py`, not the student's notebook at `modules/01_tensor/tensor.ipynb`. A syntax error in the student's notebook is invisible to this test phase -- the instructor source always runs clean. The broken notebook then gets exported into `tinytorch/core/tensor.py` without any parse check. ## Fix Add `_check_notebook_syntax()`: reads the student's notebook, compiles every code cell with Python's `compile()`, and returns the first `SyntaxError` found with the cell number and line. Called in both `complete_module` and `_complete_module_quiet` immediately before the export step, so the student sees: ``` ❌ Syntax error in your notebook -- fix it before exporting SyntaxError in tensor.ipynb cell 12, line 3: '(' was never closed if len(shape) == 1 and isinstance(shape[0], (tuple, list): ``` instead of a confusing failure in the next module. ## Test plan - [ ] Student notebook with a syntax error: `tito module complete 01` reports the error with cell + line number and exits 1 - [ ] Valid notebook: behaviour unchanged, export proceeds normally - [ ] `tito module complete --all` (quiet path) also blocked on syntax errors Co-authored-by: Chufeng Jiang <cjiang@gradcenter.cuny.edu> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-06-18 16:55:38 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/cs249r_book#27338