Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linter for detecting open files that are never closed #7

Open
mschwager opened this issue Jan 10, 2020 · 0 comments
Open

Add linter for detecting open files that are never closed #7

mschwager opened this issue Jan 10, 2020 · 0 comments

Comments

@mschwager
Copy link
Contributor

Most file IO should be using with statements to automatically close files, but there still may be instances of manual open and close calls (or lack thereof). See Reading and Writing Files.

There are lots of ways a file can be opened:

  • open
  • os.open
  • io.open (alias for builtin open)
  • tempfile.TemporaryFile|NamedTemporaryFile|SpooledTemporaryFile
  • tarfile.open
  • ZipFile.open
  • Others?

My first idea for an implementation is tracking variable instantiation of the above methods, then checking for a lack of a close call in the same scope.

Also would be good to check for a lack of closing a connection after opening one (e.g. in SQLAlchemy). There's probably lots of opportunity for this in DB connection libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant