Skip to content

Attaching using PEP 768 style code injection fails when there's a backslash in the temp path #2037

Description

@tonyroberts

When attempting to attach using PEP 768 style code injection, the code written to the temp file contains invalid characters if the temp file path contains backslashes (such as "C:\Users\xxx\AppData\Local\Temp\")

"""import os;os.remove("{tmp_file_path}");""".format(

This results in an error when the code is attempted to be run:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (<string>, line 1)

It looks like this was introduced in c7e86a1. The fix would be to escape the path on Windows when writing the file, or simply replace backslashes with forward slashes.

Environment data

  • debugpy version: 1.8.20
  • OS and version: Windows 11
  • Python version: 3.14.5
  • Using VS Code or Visual Studio: VS Code

Actual behavior

Attempting to attach to a Python 3.14 process on Windows where the temp folder has a "\" in the path fails with the error

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (<string>, line 1)

Expected behavior

It should attach to the process.

Steps to reproduce:

  1. Start a Python 3.14 process on Windows
  2. Attempt to attach to it using VS Code

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions