Skip to main content

flake8-close-io-buffers

A Flake8 plugin to detect unclosed IO buffers in your Python code. This tool helps ensure that IO objects (such as io.BytesIO and io.StringIO) are properly closed either via a context manager or an explicit .close() call.

Features

  • Detects Unclosed IO Objects:
    Reports an error (IO100) when an IO object is instantiated but not closed.

  • Supports Different Import Styles:
    Works with both:

    • Qualified imports:
      import io
      io.BytesIO()
      
    • Direct imports:
      from io import BytesIO, StringIO
      BytesIO()
      
  • Multiple Assignment Support:
    Correctly handles cases where IO objects are assigned to variables, including tuple/list assignments.

Installation

You can install the plugin from PyPI:

pip install flake8-close-io-buffers

Usage

Once installed, Flake8 will automatically load the plugin. Run Flake8 on your Python files as usual:

flake8 your_python_file.py

Configuration

By default, Flake8 may not display errors from custom plugins. To ensure that IO100 errors are reported, add the following to your Flake8 configuration file (e.g., .flake8, setup.cfg, or tox.ini):

[flake8]
extend-select = IO100

Or, run Flake8 with the select flag:

flake8 --select=IO100 your_python_file.py

Example

Consider the following code in example.py:

import io

def foo():
    io.BytesIO()  # Unclosed IO object: will trigger IO100 error

Running Flake8:

flake8 --select=IO100 example.py

Will produce an error like:

example.py:4:5: IO100 unclosed IO object instantiation not assigned to a variable

Running Tests

The project uses pytest for testing. To run the tests:

  1. Ensure you have the development dependencies installed (e.g., pytest).
  2. From the project root, run:
pytest

Contributing

Contributions are welcome! Please feel free to open issues or submit pull requests on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Release files for flake8-close-io-buffers 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-close-io-buffers 0.1.4
File Size Uploaded
flake8_close_io_buffers-0.1.4.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flake8-close-io-buffers 0.1.4
File Interpreter ABI Platform
flake8_close_io_buffers-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / flake8_close_io_buffers-0.1.4.tar.gz

Download URL flake8_close_io_buffers-0.1.4.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2e24de80bbd599d6f3d71dedba3752e19b18202838edcea1a417a67a72fcac03
BLAKE2b-256 checksum
How to use checksums
d6181a4d7e9048db0ca9c8802a6e6813dda923644574442f022b5a0cb43c3f49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release files / flake8_close_io_buffers-0.1.4-py3-none-any.whl

Download URL flake8_close_io_buffers-0.1.4-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ddce2215716cd6955978b760c14d6ee5e327022a0d75e39ad545d97a2d35ef43
BLAKE2b-256 checksum
How to use checksums
4bf22dfced9595a1bb80a5eaadd4f48b16997c0a9e25c9f6c98232e9c868d93a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page