Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#19 Warn if forgetting to call close()

open
nobody
None
5
2004-05-22
2004-05-22
Peter Åstrand
No

I've recently discovered that there are two cases in
Python which will lead to *silent* data loss (at least
on UNIX):

open("foo", "w").write("bar")

and:

def foo():
f = open("foo", "w")
f.write("bar")

If the write fails for some reason, like when out of
quota, this will not be detected. This is because the
error is reported by the system call close(). Such
errors usually raises an exception in Python, but this
does not happen in destructors. Instead, the error is
silently ignored.

I think it would be great if pychecker could warn about
this case.

Discussion