Skip to content

About

A dependency-free Python CLI with runnable examples of context manager entry, exit, exception handling, and cleanup order.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Animated header

Typing SVG

License Top language Stars Last commit

Python Context Manager Lab mark

🧭 Overview

A dependency-free Python CLI with short, labeled examples of context manager behavior. Follow entry and exit, exception propagation, opt-in suppression, generator-based managers, and ExitStack cleanup order.

✨ Features

  • 🚪 Demonstrates class-based enter and exit methods.
  • ⚠️ Shows how exceptions propagate unless exit explicitly suppresses them.
  • 🧵 Demonstrates contextlib.contextmanager with try/finally cleanup.
  • 📚 Shows ExitStack callbacks running in last-in-first-out order.

🖥️ Demo

Run the CLI to see each example printed in sequence. No external files or services are used.

⚡ Quick Start

python -m pip install -e .
context-manager-lab

Run the unit checks with python -m unittest discover -s tests.

🧰 Tech Stack

  • Python 3.10+ — contextlib, argparse, and unittest; no third-party dependencies.
  • License — MIT

🗂️ Folder Structure

python-context-manager-lab/
├── assets/mark.svg
├── src/context_manager_lab/
│   ├── __init__.py
│   └── cli.py
├── tests/test_cli.py
├── .gitignore
├── LICENSE
├── pyproject.toml
└── README.md

🛣️ Roadmap

  • Add async context manager examples.
  • Add nested resource cleanup scenarios.
  • Add examples for contextlib.ExitStack exception handling.

🤝 Contributing

Issues and pull requests are welcome. Keep examples deterministic and add tests for any new suppression or cleanup behavior.

📄 License

Released under the MIT License.

Animated footer

About

A dependency-free Python CLI with runnable examples of context manager entry, exit, exception handling, and cleanup order.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages