Skip to content

PLW1507 fix should be marked unsafe #16274

@dscorbett

Description

@dscorbett

Description

The fix for shallow-copy-environ (PLW1507) changes the program’s behavior (by design) and should therefore be marked unsafe.

$ ruff --version
ruff 0.9.6

$ cat >plw1507.py <<'# EOF'
import copy
import os
os.environ["X"] = "0"
env = copy.copy(os.environ)
os.environ["X"] = "1"
print(env["X"])
# EOF

$ python plw1507.py
1

$ ruff --isolated check --preview --select PLW1507 plw1507.py --fix
Found 1 error (1 fixed, 0 remaining).

$ cat plw1507.py
import copy
import os
os.environ["X"] = "0"
env = os.environ.copy()
os.environ["X"] = "1"
print(env["X"])

$ python plw1507.py
0

Metadata

Metadata

Assignees

Labels

fixesRelated to suggested fixes for violations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions