You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
History converter: Python console lines with escapes or triple quotes, left from #797 #877
🤖 This issue keeps the limits of the history converter that the review of pull request #797 ([History] Save session history from ALLCOM and write Python for .py scripts, #797, issue #785) found and that were left out of it on purpose. None concerns a history line that EEGLAB or an EEGPrep pop_ function writes. All concern Python typed by hand in the console and then saved with File > History scripts as a .py file. Each one behaves as on develop before #797, unless said otherwise.
The converter is _console_python_command in src/eegprep/functions/adminfunc/console.py. It receives MATLAB history and Python console input, because ALLCOM and EEG.history hold both. Its rule since #797: a line Python cannot parse is MATLAB. A line Python parses, with a keyword argument or a ['name'] index, was typed as Python and its strings are kept. Any other line Python parses has its single-quoted strings read as MATLAB strings.
An escaped quote in a Python line with no keyword argument and no ['name'] index.EEG.update({'setname': 'don\'t'}) comes out as broken Python. EEG.update({'notes': 'line1\nline2'}) and print('a\nb') keep the backslash as a character. A dictionary literal with string keys could count as Python too.
Triple-quoted strings that hold a quote followed by ;, # or a bracket, for example EEG['notes'] = '''x'; y'''.
Two transposes after a variable named r, b, f or u, x = r' * s';, which is also a valid Python prefixed string and is read as Python.
A MATLAB comment of one word, x = 1 % note, which is also a valid Python modulo and is left as it is.
A whole session script pasted as one cell in the console, ending with eegprep.eeglab('redraw', workspace=globals()): the console records the cell as one command, as it does for any cell that assigns EEG.
LASTCOM after eegh(-1) keeps the blank at the end of a pop_newset line (remove_history in src/eegprep/functions/guifunc/session.py), so the next console command can add that line a second time.
A # comment that ends with a semicolon, x = 1 # note;, loses the semicolon.
The full text of the three review passes by Gemini is in the "Code review" comment of #797.
Six of the seven items (1-5, 7) are about the Python-or-MATLAB detection rule that #797 adds to _console_python_command. #797 is still open, so develop does not have that rule yet: develop's _matlab_strings_to_python still reads every single-quoted string as MATLAB. A fix branched from develop would conflict with #797 or have to copy it. Item 6 is in remove_history, but the duplicate it causes comes from the dedupe that #797 adds.
The issue lists seven heuristic edge cases across two modules. It is not one small bug, and it depends on an unmerged PR, so no PR is opened. Suggested order once #797 merges:
Item 6 on its own: set LASTCOM to ALLCOM[-1].strip(), or compare stripped commands in the dedupe. Regression test in tests/test_console_workspace.py.
Items 1, 2 and 7 together: when ast.parse succeeds, take strings, escapes and # comments from Python's tokenize instead of the hand scanner in _split_history_statements / _matlab_strings_to_python. Count a backslash escape inside a quote, or a dict literal with string keys, as a sign the line is Python (item 1).
Items 3 and 4 are truly ambiguous (r' * s', 1 % note are valid in both languages). Suggest documenting them as known limitations instead of adding more heuristics.
Item 5 (a whole script pasted as one cell) is a design choice: should a cell be split into several history entries? It needs a decision before code.
Open question: fix items 3-5, or close them as known limitations in the history docs?
Activity
claude commentedon Nov 29, 2026
🤖 Plan:
Research
Six of the seven items (1-5, 7) are about the Python-or-MATLAB detection rule that #797 adds to
_console_python_command. #797 is still open, so develop does not have that rule yet: develop's_matlab_strings_to_pythonstill reads every single-quoted string as MATLAB. A fix branched from develop would conflict with #797 or have to copy it. Item 6 is inremove_history, but the duplicate it causes comes from the dedupe that #797 adds.Relevant code (#797 head
52a5ecc)console.py#L908-L925: converter entry, comment splitting (item 7)console.py#L940-L945: Python-or-MATLAB rule (items 1, 3, 4)console.py#L1042-L1085: statement splitter,;/#/%handling (items 2, 4, 7)console.py#L1087: string conversion (items 1, 2)session.py#L670-L677:LASTCOMaftereegh(-1)(item 6)Proposed approach (needs human review)
The issue lists seven heuristic edge cases across two modules. It is not one small bug, and it depends on an unmerged PR, so no PR is opened. Suggested order once #797 merges:
LASTCOMtoALLCOM[-1].strip(), or compare stripped commands in the dedupe. Regression test intests/test_console_workspace.py.ast.parsesucceeds, take strings, escapes and#comments from Python'stokenizeinstead of the hand scanner in_split_history_statements/_matlab_strings_to_python. Count a backslash escape inside a quote, or a dict literal with string keys, as a sign the line is Python (item 1).r' * s',1 % noteare valid in both languages). Suggest documenting them as known limitations instead of adding more heuristics.Open question: fix items 3-5, or close them as known limitations in the history docs?