Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output cells not correct with special input #2534

Closed
rchiodo opened this issue Dec 18, 2019 · 4 comments
Closed

Output cells not correct with special input #2534

rchiodo opened this issue Dec 18, 2019 · 4 comments
Assignees

Comments

@rchiodo
Copy link
Contributor

rchiodo commented Dec 18, 2019

This code here:

for i in range(10):
    if i == 8 :
        clear_output(True)
        print('bar 8 {0}'.format(i))
    elif (i % 2 == 0):
        print('bar even')
        display('bar-d {0}'.format(i))
    else: 
        display('bar-d {0}'.format(i))
        print('bar odd')

Produces this for us:

bar even
'bar-d 9'
bar odd
bar even
bar odd
bar even
bar odd
bar even
bar 8 8
bar odd

And this for jupyter:

bar 8 8
'bar-d 9'
bar odd
@rchiodo
Copy link
Contributor Author

rchiodo commented Dec 18, 2019

This is related to trying to match the output concatenation strategy that jupyter takes.

@rchiodo
Copy link
Contributor Author

rchiodo commented Dec 18, 2019

This might fix the problem:

Change:

    private handleStreamMesssage(msg: KernelMessage.IStreamMsg, clearState: Map<string, boolean>, cell: ICell, trimFunc: (str: string) => string) {
        // Might already have a stream message. If so, just add on to it.
        const data: nbformat.ICodeCell = cell.data as nbformat.ICodeCell;
        const existing = data.outputs.length > 0 && data.outputs[data.outputs.length - 1].output_type === 'stream' ? data.outputs[data.outputs.length - 1] : undefined;
        if (existing) {
            // If clear pending, then don't add.
            if (clearState.get('stream')) {
                clearState.delete('stream'); <-- Eliminate this line so that the delete happens after this point
                existing.text = msg.content.text;
            } else {
                // tslint:disable-next-line:restrict-plus-operands
                existing.text = existing.text + msg.content.text;
                existing.text = trimFunc(formatStreamText(concatMultilineStringOutput(existing.text)));
            }
        } else {
            // Create a new stream entry
            const output: nbformat.IStream = {
                output_type: 'stream',
                name: msg.content.name,
                text: trimFunc(formatStreamText(concatMultilineStringOutput(msg.content.text)))
            };
            this.addToCellData(cell, output, clearState);
        }
    }

@rchiodo
Copy link
Contributor Author

rchiodo commented Jan 8, 2020

Only fix this if the suggestion works.

@rchiodo rchiodo self-assigned this Feb 13, 2020
@IanMatthewHuff
Copy link
Member

Validated.

@lock lock bot locked as resolved and limited conversation to collaborators Feb 22, 2020
@microsoft microsoft unlocked this conversation Nov 13, 2020
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants