Skip to content

Commit a820d0d

Browse files
committed
pySCG: fix invalid Path() kwarg in CWE-798 compliant example
Remove invalid 'exist_ok=True' parameter from Path() constructor. This parameter belongs to Path.mkdir(), not Path(). The invalid usage triggers DeprecationWarning in Python 3.12+ and will cause errors in Python 3.14+. The file is created by open() on the next line, so exist_ok was never needed here. This is a bug fix with no behavior change. Signed-off-by: tommcd <[email protected]>
1 parent c0dfba9 commit a820d0d

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

docs/Secure-Coding-Guide-for-Python/CWE-693/CWE-798/compliant01.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: OpenSSF project contributors
22
# SPDX-License-Identifier: MIT
33
"""Compliant Code Example"""
4-
# EXPECTED_FAILURE: uses deprecated Path() kwargs, scheduled for removal in Python 3.14
54

65
import logging
76
from pathlib import Path
@@ -43,7 +42,7 @@ def setUp(self):
4342
config["LOGGING"] = {
4443
"level": "DEBUG",
4544
}
46-
self.config_file_path = Path("config.ini", exist_ok=True)
45+
self.config_file_path = Path("config.ini")
4746
with open(self.config_file_path, "w", encoding="utf-8") as config_file:
4847
config.write(config_file)
4948
self.config_file_path.chmod(0o400)

0 commit comments

Comments
 (0)