Skip to content

builtins.globals() fails to update after a comprehension with colliding variable in Python 3.12 #1849

@kycutler

Description

@kycutler

Environment data

  • debugpy version: 1.8.12
  • OS and version: Windows 11
  • Python version (& distribution if applicable, e.g. Anaconda): 3.12.8
  • Using VS Code or Visual Studio: VS Code

Actual behavior

Run and debug the following, with a breakpoint on the last line:

# Global variable
foo = None

# Comprehension with colliding local variable
[foo for foo in [0]]

# Breakpoint here
debugger()

While paused, evaluate the following in debug console:

import builtins
builtins.globals()["abc"] = 123
builtins.globals()["abc"]

Notice the last evaluation fails with a KeyError, even though it should have been set.

This issue only reproduces under the following circumstances:

  • Python 3.12 (any patch version -- but 3.11 and 3.13 both work)
  • The code is in global scope
  • The iteration variable in the comprehension collides with the global variable

Expected behavior

The assignment to builtins.globals() should persist between evaluations

Metadata

Metadata

Assignees

Labels

needs reproIssue has not been reproduced yet

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions