Repository navigation
fix: record cells mixing magic lines with Python code (#17) - #57
Merged
Merged
Conversation
これまでは先頭が `!` `%` `%%` で始まるセルを一律スキップしていたため、 `%time` のようなマジック行と通常コードが混在したセルが丸ごと記録対象外と なり、変数(例: `a = [0] * (2 ** 25)`)が依存グラフに残らなかった。 IPython本体と同じ入力変換器(shell.transform_cell)でセルを正規Pythonへ 変換し、変換後のコードが get_ipython() のマジック/シェル呼び出しのみで 構成されているかをASTで判定するように変更。純粋なマジックセルのみスキップし、 混在セルは変換後コードで record_event する。これにより文字列内の `%` (例: `y = '100%'`)も誤判定しない。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
issue #17 の修正。
%timeのようなマジック行と通常のPythonコードが混在したセルが、これまで丸ごと記録対象外(スキップ)になっていた問題を直す。このセルは先頭が
%で始まるため__skip_recordがTrueを返し、変数aが依存グラフに記録されず、チェックポイントにも残らなかった。変更内容(案3:
transform_cell採用)self.shell.transform_cell()でセルを正規のPythonコードへ変換する。マジック/シェルはget_ipython().run_line_magic(...)などへ展開され、ast.parse可能になる。__is_pure_magic_cell)。純粋なマジックセル(%matplotlib inline、!ls等)のみスキップし、混在セルは記録する。record_eventには変換後のコードを渡すため、find_input_varsのast.parseが壊れなくなる。復元時はshell.run_cellがマジックをネイティブに扱うため整合する。%(例:y = '100%')を誤ってマジック扱いしない堅牢性も得られる。__skip_recordは削除。テスト
tests/test_skip_record.pyを新ロジックに合わせて更新し、混在セル・複数マジック・空セルのケースを追加。uv run pytest→ 59 passeduv run flake8/uv run mypy→ クリーンuv run black/uv run isort適用済みclose #17
🤖 Generated with Claude Code