types-greenlet

3.4.0.20260409 · active · verified Sun Apr 12

types-greenlet provides external type hints (stubs) for the `greenlet` library, enabling static type checkers like MyPy and Pyright to analyze code using `greenlet` effectively. It is part of the `typeshed` project, which maintains a collection of high-quality type annotations for many Python packages. Releases are frequent, often daily, to keep pace with updates in the `greenlet` library and general typeshed improvements. The current version, 3.4.0.20260409, aims to provide accurate annotations for `greenlet==3.3.*`.

Warnings

Install

Imports

Quickstart

This example demonstrates basic usage of the `greenlet` library. When `types-greenlet` is installed, a static type checker will understand the types associated with `greenlet.greenlet`, `greenlet.getcurrent()`, and their methods, providing better analysis and error detection without needing direct imports from `types-greenlet` itself.

import greenlet

def worker_function(name: str) -> str:
    print(f"Worker {name} started.")
    # Simulate some work, then switch back to parent
    result = f"Hello from {name}!"
    parent = greenlet.getcurrent().parent
    if parent:
        return parent.switch(result)
    return result

def main_function():
    main = greenlet.getcurrent()
    g1 = greenlet.greenlet(worker_function)
    g2 = greenlet.greenlet(worker_function)

    print("Main function: Switching to g1")
    res1 = g1.switch("Alice")
    print(f"Main function: Received {res1}")

    print("Main function: Switching to g2")
    res2 = g2.switch("Bob")
    print(f"Main function: Received {res2}")

    print("Main function: All done.")

if __name__ == "__main__":
    main_function()

# To verify type checking (requires mypy installed):
# Save this code as `example.py`
# Run `mypy example.py` in your terminal. With types-greenlet installed, it should pass without errors for greenlet-specific types.

view raw JSON →