blank-line-after-blocks


Nameblank-line-after-blocks JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryA Python formatter to automatically add blank lines after if/for/while/with/try blocks
upload_time2025-08-28 01:51:21
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords formatter code-style blank-lines python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # blank-line-after-blocks

A Python formatter to automatically add blank lines after if/for/while/with/try
blocks to improve code readability.

## Installation

```bash
pip install blank-line-after-blocks
```

## Usage

### Command Line

```bash
# Format Python files
blank-line-after-blocks file1.py file2.py

# Format Jupyter notebooks
blank-line-after-blocks-jupyter notebook1.ipynb notebook2.ipynb
```

### Pre-commit Hook

Add this to your `.pre-commit-config.yaml`:

```yaml
repos:
  - repo: https://github.com/jsh9/blank-line-after-blocks
    rev: 0.1.0
    hooks:
      - id: blank-line-after-blocks
      - id: blank-line-after-blocks-jupyter
```

## What it does

This tool automatically adds one blank line after the end of:

- `if` statements
- `for` loops
- `while` loops
- `with` statements
- `try`/`except`/`finally` blocks

This improves code readability by providing visual separation between blocks
and subsequent code.

## Examples

### Basic if and for blocks

```diff
  if condition:
      do_something()
+
  next_statement()

  for item in items:
      process(item)
+
  final_step()
```

### Try/except blocks with context managers

```diff
  def process_files(filenames):
      results = []
      for filename in filenames:
          try:
              with open(filename) as f:
                  data = json.load(f)
+
              results.append(data)
          except FileNotFoundError:
              print(f'File {filename} not found')
          except json.JSONDecodeError:
              print(f'Invalid JSON in {filename}')
+
      return results
```

### Nested blocks in class methods

```diff
  class TestClass:
      def method(self):
          try:
              if self.condition():
                  with self.get_context():
                      self.do_work()
+
                  self.cleanup()
+
          except Exception as e:
              self.handle_error(e)
+
          print('method complete')
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "blank-line-after-blocks",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "Your Name <your.email@example.com>",
    "keywords": "formatter, code-style, blank-lines, python",
    "author": null,
    "author_email": "Your Name <your.email@example.com>",
    "download_url": "https://files.pythonhosted.org/packages/16/9e/bb1b2cec8ef8ffcdf1dcd8315da1f1f37a7beb7175d394d924fe5cf25136/blank_line_after_blocks-0.1.1.tar.gz",
    "platform": null,
    "description": "# blank-line-after-blocks\n\nA Python formatter to automatically add blank lines after if/for/while/with/try\nblocks to improve code readability.\n\n## Installation\n\n```bash\npip install blank-line-after-blocks\n```\n\n## Usage\n\n### Command Line\n\n```bash\n# Format Python files\nblank-line-after-blocks file1.py file2.py\n\n# Format Jupyter notebooks\nblank-line-after-blocks-jupyter notebook1.ipynb notebook2.ipynb\n```\n\n### Pre-commit Hook\n\nAdd this to your `.pre-commit-config.yaml`:\n\n```yaml\nrepos:\n  - repo: https://github.com/jsh9/blank-line-after-blocks\n    rev: 0.1.0\n    hooks:\n      - id: blank-line-after-blocks\n      - id: blank-line-after-blocks-jupyter\n```\n\n## What it does\n\nThis tool automatically adds one blank line after the end of:\n\n- `if` statements\n- `for` loops\n- `while` loops\n- `with` statements\n- `try`/`except`/`finally` blocks\n\nThis improves code readability by providing visual separation between blocks\nand subsequent code.\n\n## Examples\n\n### Basic if and for blocks\n\n```diff\n  if condition:\n      do_something()\n+\n  next_statement()\n\n  for item in items:\n      process(item)\n+\n  final_step()\n```\n\n### Try/except blocks with context managers\n\n```diff\n  def process_files(filenames):\n      results = []\n      for filename in filenames:\n          try:\n              with open(filename) as f:\n                  data = json.load(f)\n+\n              results.append(data)\n          except FileNotFoundError:\n              print(f'File {filename} not found')\n          except json.JSONDecodeError:\n              print(f'Invalid JSON in {filename}')\n+\n      return results\n```\n\n### Nested blocks in class methods\n\n```diff\n  class TestClass:\n      def method(self):\n          try:\n              if self.condition():\n                  with self.get_context():\n                      self.do_work()\n+\n                  self.cleanup()\n+\n          except Exception as e:\n              self.handle_error(e)\n+\n          print('method complete')\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Python formatter to automatically add blank lines after if/for/while/with/try blocks",
    "version": "0.1.1",
    "project_urls": {
        "Changelog": "https://github.com/jsh9/blank-line-after-blocks/blob/main/CHANGELOG.md",
        "Homepage": "https://github.com/jsh9/blank-line-after-blocks",
        "Issues": "https://github.com/jsh9/blank-line-after-blocks/issues",
        "Repository": "https://github.com/jsh9/blank-line-after-blocks.git"
    },
    "split_keywords": [
        "formatter",
        " code-style",
        " blank-lines",
        " python"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "58760e791c217f0d97fa65b4ef7f7b7bbc0ca92a00a390c132411ee97adeb0b6",
                "md5": "dac9727b79d03b16787ed1f84633f7d5",
                "sha256": "e63448119b3dd26cec0a3bae5ffa9d27855ecb8d05133cae820cd22978343ee0"
            },
            "downloads": -1,
            "filename": "blank_line_after_blocks-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dac9727b79d03b16787ed1f84633f7d5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 8308,
            "upload_time": "2025-08-28T01:51:20",
            "upload_time_iso_8601": "2025-08-28T01:51:20.513259Z",
            "url": "https://files.pythonhosted.org/packages/58/76/0e791c217f0d97fa65b4ef7f7b7bbc0ca92a00a390c132411ee97adeb0b6/blank_line_after_blocks-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "169ebb1b2cec8ef8ffcdf1dcd8315da1f1f37a7beb7175d394d924fe5cf25136",
                "md5": "6b46bbc7e63255a2f2f897b55aee9400",
                "sha256": "9c2a33a55a4b2b0be19b0aacfce71387b77d51ba75e71f635da1f4e206473b77"
            },
            "downloads": -1,
            "filename": "blank_line_after_blocks-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "6b46bbc7e63255a2f2f897b55aee9400",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 27841,
            "upload_time": "2025-08-28T01:51:21",
            "upload_time_iso_8601": "2025-08-28T01:51:21.671207Z",
            "url": "https://files.pythonhosted.org/packages/16/9e/bb1b2cec8ef8ffcdf1dcd8315da1f1f37a7beb7175d394d924fe5cf25136/blank_line_after_blocks-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-28 01:51:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jsh9",
    "github_project": "blank-line-after-blocks",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "blank-line-after-blocks"
}
        
Elapsed time: 1.19498s