Skip to content

Using smart send with REPL leads to NameError for every line of code #25117

Closed

Description

@John-Polo

Type: Bug

Behaviour

Expected behavior: Inside a Python file, at a line, for example:
import numpy as np
use smart send ('shift+enter') to run REPL and watch code results. Move to next line and do the same thing.

Actual behavior: Editing in a Python file (.py) and using Smart Send with the VS Code REPL, each line of code sends as "deprecated", which in turn returns a NameError in the REPL window.

This doesn't happen in interactive sessions in the Python terminal in Code.

Steps to reproduce:

  1. Start Code with 'code .' from cmd prompt window where I've activated a conda environment.
  2. In current .py file in editor, use 'shift+enter' to run line.
  3. Python REPL window prints "deprecated" and reports a traceback with error:
    Traceback (most recent call last):
    File "c:\Users\japolo.vscode\extensions\ms-python.python-2025.6.1-win32-x64\python_files\python_server.py", line 133, in exec_user_input
    retval = callable_(user_input, user_globals)
    File "", line 1, in
    NameError: name 'deprecated' is not defined

Diagnostic data

There are no logs in the Output Panel. There are messages in the Problems panel:
[{
"resource": "Untitled-1.ipynb",
"owner": "python",
"severity": 8,
"message": ""return" can be used only within a function",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 7
},{
"resource": "Untitled-1.ipynb",
"owner": "python",
"code": {
"value": "reportUndefinedVariable",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUndefinedVariable.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 4,
"message": ""directory" is not defined",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 31,
"endLineNumber": 1,
"endColumn": 40
},{
"resource": "Untitled-1.ipynb",
"owner": "python",
"code": {
"value": "reportUndefinedVariable",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUndefinedVariable.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 4,
"message": ""extension" is not defined",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 54,
"endLineNumber": 1,
"endColumn": 63
},{
"resource": "Untitled-1.ipynb",
"owner": "python",
"code": {
"value": "reportUndefinedVariable",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUndefinedVariable.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 4,
"message": ""deprecated" is not defined",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 11
},{
"resource": "Untitled-1.ipynb",
"owner": "python",
"code": {
"value": "reportUndefinedVariable",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUndefinedVariable.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 4,
"message": ""deprecated" is not defined",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 11
},{
"resource": "Untitled-1.ipynb",
"owner": "python",
"code": {
"value": "reportUndefinedVariable",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUndefinedVariable.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 4,
"message": ""deprecated" is not defined",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 11
},{
"resource": "Untitled-1.ipynb",
"owner": "python",
"code": {
"value": "reportUndefinedVariable",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUndefinedVariable.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 4,
"message": ""deprecated" is not defined",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 11
},{
"resource": "Untitled-1.ipynb",
"owner": "python",
"code": {
"value": "reportUndefinedVariable",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUndefinedVariable.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 4,
"message": ""deprecated" is not defined",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 11
},{
"resource": "Untitled-1.ipynb",
"owner": "python",
"code": {
"value": "reportUndefinedVariable",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUndefinedVariable.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 4,
"message": ""deprecated" is not defined",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 11
},{
"resource": "Untitled-1.ipynb",
"owner": "python",
"code": {
"value": "reportUndefinedVariable",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUndefinedVariable.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 4,
"message": ""deprecated" is not defined",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 11
},{
"resource": "Untitled-1.ipynb",
"owner": "python",
"code": {
"value": "reportUndefinedVariable",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUndefinedVariable.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 4,
"message": ""deprecated" is not defined",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 1,
"endLineNumber": 1,
"endColumn": 11
}]
[{
"resource": "Untitled-2",
"owner": "python",
"severity": 8,
"message": "Expected one or more symbol names after "import"",
"source": "Pylance",
"startLineNumber": 8,
"startColumn": 17,
"endLineNumber": 9,
"endColumn": 1
}]
[{
"resource": "Untitled-1",
"owner": "python",
"code": {
"value": "reportUndefinedVariable",
"target": {
"$mid": 1,
"path": "/microsoft/pylance-release/blob/main/docs/diagnostics/reportUndefinedVariable.md",
"scheme": "https",
"authority": "github.com"
}
},
"severity": 4,
"message": ""os" is not defined",
"source": "Pylance",
"startLineNumber": 7,
"startColumn": 17,
"endLineNumber": 7,
"endColumn": 19
}]

Image

Activity

  1. github-actions commented on May 29, 2025

    @github-actions

    Hi John Polo (@John-Polo), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.


    Potentially Related Issues:


    The team will respond to your issue shortly. Please note this is a trial feature and may not be fully accurate. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or was incorrect, please give it a 👎. Your feedback helps us improve!

  2. added
    bugIssue identified by VS Code Team member as probable bug
    and removed
    triage-neededNeeds assignment to the proper sub-team
    on Jun 10, 2025
  3. anthonykim1 commented on Jun 19, 2025

    @anthonykim1

    Hi John Polo (@John-Polo) Apologies for late response.

    Do you mind sharing your content of the Python file?
    I believe this is happening because you have either deprecated (python2 code) in your Python file, or smart send is failing somehow with some code in your Python file.

    It would also help to turn off the smart send setting in your case via python.REPL.enableREPLSmartSend

  4. jlewonick commented on Jun 20, 2025

    @jlewonick

    Also ran into this. I'm following along Python's tutorial and I'm saving files for each chapter.
    https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions

    [x, x**2 for x in range(6)]
    was my offending line - I commented it out but I put it in there so I could see the error in action

    https://pastebin.com/1NLeALQy

  5. John-Polo commented on Jun 23, 2025

    @John-Polo
    Author

    Anthony Kim (@anthonykim1) This is the code:

    import PIL.Image
    import pandas as pd
    import numpy as np
    import cv2
    import os
    import glob
    from pathlib import Path
    import matplotlib as plt
    import PIL
    from PIL import Image, ImageEnhance
    import statistics
    from math import ceil
    
    def list_files_with_glob(directory, extension):
        return glob.glob(os.path.join(directory, '**', '*' + extension), recursive=True)
    
    files_directory = 'Z:/Late_blight/ms3/lamp/bright'
    ftype_pat = '*.jpg'
    
    # Make a list of all the files in the directory
    chiplist1 = list_files_with_glob(files_directory, ftype_pat)
    

    I don't know what's different this time around, but the REPL is working. Thanks for following up. I'll close this.

  6. John-Polo commented on Jun 23, 2025

    @John-Polo
    Author

    jlewonick I don't know a lot about Python, so take my comment with some caution. Python's list comprehensions are definitely compliant with Python 3. While you may be getting an error from executing a list comprehension, I don't think it's actually behind the "deprecated" error you're getting. There might be another issue that's eliciting that error. Sorry, I don't know anything more to tell you. Maybe Anthony Kim (@anthonykim1) will weigh in on the issue. Good luck.

  7. guoci commented on Aug 26, 2025

    @guoci

    This can be reproduced by having a syntax error anywhere in the file. I have just sent a pull request #25421 to clarify the warning message.

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

Metadata

Metadata

Labels

area-replbugIssue 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