Skip to content

Commit 010c815

Browse files
committed
fixed unclosed file handle in py_scadparser
1 parent 1ece137 commit 010c815

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

solid/py_scadparser/scad_parser.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,6 @@ def p_error(p):
244244
print("syntex error")
245245

246246
def parseFile(scadFile):
247-
from pathlib import Path
248-
p = Path(scadFile)
249-
f = p.open()
250247

251248
lexer = lex.lex()
252249
parser = yacc.yacc()
@@ -264,8 +261,10 @@ def parseFile(scadFile):
264261
ScadTypes.INCLUDE: lambda x: includes.append(x),
265262
}
266263

267-
for i in parser.parse(f.read(), lexer=lexer):
268-
appendObject[i.getType()](i)
264+
from pathlib import Path
265+
with Path(scadFile).open() as f:
266+
for i in parser.parse(f.read(), lexer=lexer):
267+
appendObject[i.getType()](i)
269268

270269
return uses, includes, modules, functions, globalVars
271270

0 commit comments

Comments
 (0)