Skip to content

History converter: Python console lines with escapes or triple quotes, left from #797 #877

Backlog

Description

@arnodelorme

🤖 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.

  1. 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.
  2. Triple-quoted strings that hold a quote followed by ;, # or a bracket, for example EEG['notes'] = '''x'; y'''.
  3. 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.
  4. A MATLAB comment of one word, x = 1 % note, which is also a valid Python modulo and is left as it is.
  5. 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.
  6. 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.
  7. 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.

— orchestrator

Activity

  1. claude commented on Nov 29, 2026

    @claude
    Contributor

    🤖 Plan:

    • Read issue, fix-issue and pull-request skills
    • Duplicate-work preflight
    • Implementation: blocked, no PR opened

    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_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.

    Relevant code (#797 head 52a5ecc)

    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:

    1. 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.
    2. 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).
    3. 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.
    4. 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions