Skip to content

Commit cb1c7e5

Browse files
sigma67madebr
authored andcommitted
fix ResourceWarning: unclosed file
1 parent c0b68ed commit cb1c7e5

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

cmake_file_api/kinds/cache/v2.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CacheV2":
8484

8585
@classmethod
8686
def from_path(cls, path: Path, reply_path: Path) -> "CacheV2":
87-
dikt = json.load(path.open())
87+
with path.open() as file:
88+
dikt = json.load(file)
8889
return cls.from_dict(dikt, reply_path)
8990

9091
def __repr__(self) -> str:

cmake_file_api/kinds/cmakeFiles/v1.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CMakeFilesV1":
5252

5353
@classmethod
5454
def from_path(cls, path: Path, reply_path: Path) -> "CMakeFilesV1":
55-
dikt = json.load(path.open())
55+
with path.open() as file:
56+
dikt = json.load(file)
5657
return cls.from_dict(dikt, reply_path)
5758

5859
def __repr__(self) -> str:

cmake_file_api/kinds/codemodel/v2.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "CodemodelV2":
174174

175175
@classmethod
176176
def from_path(cls, path: Path, reply_path: Path) -> "CodemodelV2":
177-
dikt = json.load(path.open())
177+
with path.open() as file:
178+
dikt = json.load(file)
178179
return cls.from_dict(dikt, reply_path)
179180

180181
def get_configuration(self, name: str) -> CMakeConfiguration:

cmake_file_api/kinds/configureLog/v1.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "ConfigureLogV1":
2727

2828
@classmethod
2929
def from_path(cls, path: Path, reply_path: Path) -> "ConfigureLogV1":
30-
dikt = json.load(path.open())
30+
with path.open() as file:
31+
dikt = json.load(file)
3132
return cls.from_dict(dikt, reply_path)
3233

3334
def __repr__(self) -> str:

cmake_file_api/kinds/toolchains/v1.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def from_dict(cls, dikt: dict[str, Any], reply_path: Path) -> "ToolchainsV1":
9999

100100
@classmethod
101101
def from_path(cls, path: Path, reply_path: Path) -> "ToolchainsV1":
102-
dikt = json.load(path.open())
102+
with path.open() as file:
103+
dikt = json.load(file)
103104
return cls.from_dict(dikt, reply_path)
104105

105106
def __repr__(self) -> str:

cmake_file_api/reply/index/v1.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,6 @@ def from_dict(cls, dikt: dict[str, Any]) -> "CMakeReplyFileV1":
157157

158158
@classmethod
159159
def from_path(cls, path: Path) -> "CMakeReplyFileV1":
160-
dikt = json.load(path.open())
160+
with path.open() as file:
161+
dikt = json.load(file)
161162
return cls.from_dict(dikt)

0 commit comments

Comments
 (0)