microsoft / microsoft/vscode-python-debugger

PowerShell script debugpy.ps1 incorrectly handles multiple arguments passed as an array

Open Beginner friendly
#1,024 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

triage-needed
Dominant language
TypeScript
Stars
180
Forks
126
Avg merge
2d 3h
Merged PRs (30d)
3

Description

Description:

When using the PowerShell wrapper script debugpy.ps1 to debug a Python script that accepts multiple command-line arguments, the arguments are not properly passed through to the Python script when provided as an array.

Steps to Reproduce:

  1. Create a test Python script (test.py):
import sys
print(sys.argv)
  1. Create a PowerShell script (run.ps1):
$arg_list = @('arg1', 'arg2')
$file = "test.py"

& python $file $arg_list  # Works correctly
& debugpy $file $arg_list  # Fails - arguments are concatenated
  1. Run the PowerShell script:
.\run.ps1

Actual Result:

['test.py', 'arg1', 'arg2']
['test.py', 'arg1 arg2']

Expected Result:

['test.py', 'arg1', 'arg2']
['test.py', 'arg1', 'arg2']

Root Cause:
The current debugpy.ps1 script passes $args directly to the Python command without using splatting (@args). When an array is passed to the script, PowerShell's $args receives it as a single object rather than expanding it into multiple arguments.

Current code:

if ($os -eq [System.PlatformID]::Win32NT) {
    python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args
} else {
    python3 $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args
}

Proposed Fix:
Use the splatting operator (@args) instead of $args to properly expand array arguments:

if ($os -eq [System.PlatformID]::Win32NT) {
    python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client @args
} else {
    python3 $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client @args
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in the debugpy.ps1 wrapper, focusing on how its argument list is passed to the Python command in each OS branch. Reproduce the issue with the provided run.ps1 and test.py scripts, then verify that array arguments remain separate and produce the expected sys.argv output.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, python
Domain
cli
Issue type
Bug
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.