Skip to content

Bug in running selected code in terminal #770

Closed

Description

@bethandtownes

Environment data

VS Code version: 1.19.3 (1.19.3)
Python Extension version: 2018.1.0
Python Version: 3.6.1
OS and version: MAC OS High Sierra 10.13.1

Actual behavior

When I run the following code using the Run Selection in Python Terminal Command, it gives me an error saying SyntaxError: invalid syntax. However, when I remove #BUGLINE2 in the for loop, this script becomes runnable using the same command. So I think there is a bug in parsing multiline comments written by #.

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
from sklearn import neighbors, datasets

n_neighbors = 15

# import some data to play with
iris = datasets.load_iris()

# we only take the first two features. We could avoid this ugly
# slicing by using a two-dim dataset
X = iris.data[:, :2]
y = iris.target

h = .02  # step size in the mesh

# Create color maps
cmap_light = ListedColormap(['#FFAAAA', '#AAFFAA', '#AAAAFF'])
cmap_bold = ListedColormap(['#FF0000', '#00FF00', '#0000FF'])

for weights in ['uniform', 'distance']:
    clf = neighbors.KNeighborsClassifier(n_neighbors, weights=weights)
    clf.fit(X, y)
    # BUGLINE1
    # BUGLINE2
    x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
    y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
    xx, yy = np.meshgrid(np.arange(x_min, x_max, h),np.arange(y_min, y_max, h))
    Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
    # Put the result into a color plot
    Z = Z.reshape(xx.shape)
    plt.figure()
    plt.pcolormesh(xx, yy, Z, cmap=cmap_light)
    # Plot also the training points
    plt.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold,edgecolor='k', s=20)
    plt.xlim(xx.min(), xx.max())
    plt.ylim(yy.min(), yy.max())
plt.show()

Expected behavior

Should run smoothly and produce a few nice plots since the code is directly copied from Scikitlearn library.

Steps to reproduce:

Just copy and paste into vscode, select all and choose Run Selection in Python Terminal.

Logs

Output from Python output panel

>>> for weights in ['uniform', 'distance']:
...     clf = neighbors.KNeighborsClassifier(n_neighbors, weights=weights)
...     clf.fit(X, y)
...     # BUGLINE1
...     # BUGLINE2
...     x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
...     y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
...     xx, yy = np.meshgrid(np.arange(x_min, x_max, h),np.arange(y_min, y_max, h))
...     Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
...     # Put the result into a color plot
...     Z = Z.reshape(xx.shape)
...     plt.figure()
...                    xx,                   xx,       #P                   xx,                   xer(        xx,                edgecolor='k', s=20)
  File "<stdin>", line 13
    xx,                   xx,       # P xx,                   xer(                   xx,        edgecolor='k', s=20)
    ^
IndentationError: unexpected indent
>>>     plt.xlim(xx.min(), xx.max())
  File "<stdin>", line 1
    plt.xlim(xx.min(), xx.max())
    ^
IndentationError: unexpected indent
>>>     plt.ylim(yy.min(), yy.max())
  File "<stdin>", line 1
    plt.ylim(yy.min(), yy.max())
    ^
IndentationError: unexpected indent
>>> plt.show()

Output from Console window (Help->Developer Tools menu)

  ERR Cannot read property 'isEmpty' of undefined: TypeError: Cannot read property 'isEmpty' of undefined
	at PythonDefinitionProvider.provideDefinition (/Users/daqiansun/.vscode/extensions/ms-python.python-2018.1.0/out/client/providers/definitionProvider.js:36:34)
	at PythonDefinitionProvider.descriptor.value (/Users/daqiansun/.vscode/extensions/ms-python.python-2018.1.0/out/client/telemetry/index.js:40:43)
	at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:440:20
	at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:93:1004
	at new n.Class.derive._oncancel (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:74:234)
	at Object.t.asWinJsPromise (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:93:967)
	at e.provideDefinition (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:439:963)
	at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:452:421
	at e._withAdapter (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:451:24)
	at e.$provideDefinition (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:452:383)
	at t.e.invoke (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:516:87)
	at e._invokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:357:580)
	at e._receiveOneMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:357:270)
	at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:356:206
	at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:358:204
	at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/node/extensionHostProcess.js:85:988

Activity

  1. DonJayamanne commented on Feb 13, 2018

    @DonJayamanne

    I can replicate the exact same behaviour in a terminal window outside of VS Code (just use Mac Terminal).
    I.e. its not an issue with the extension nor VS Code.

  2. locked as resolved and limited conversation to collaborators on Jul 12, 2018
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

    area-terminalbugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions