{"id":6930,"library":"types-futures","title":"types-futures","description":"types-futures provides static type annotations (stubs) for the `concurrent.futures` module, which is part of Python's standard library. It enables type checkers like MyPy, Pyright, or PyCharm to perform static analysis and provide type hints for code utilizing thread and process pools. This package is maintained by the Typeshed project and is released automatically to PyPI, often daily, to keep up with changes in the runtime library.","status":"active","version":"3.3.8","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","futures","concurrent","typeshed"],"install":[{"cmd":"pip install types-futures","lang":"bash","label":"Install types-futures"}],"dependencies":[],"imports":[{"symbol":"Future","correct":"from concurrent.futures import Future"},{"symbol":"ThreadPoolExecutor","correct":"from concurrent.futures import ThreadPoolExecutor"},{"symbol":"ProcessPoolExecutor","correct":"from concurrent.futures import ProcessPoolExecutor"},{"symbol":"as_completed","correct":"from concurrent.futures import as_completed"},{"symbol":"wait","correct":"from concurrent.futures import wait"}],"quickstart":{"code":"from concurrent.futures import ThreadPoolExecutor, Future\nfrom typing import List\n\ndef long_running_task(n: int) -> int:\n    import time\n    time.sleep(0.1)\n    return n * n\n\ndef main() -> None:\n    with ThreadPoolExecutor(max_workers=5) as executor:\n        futures: List[Future[int]] = [\n            executor.submit(long_running_task, i) for i in range(10)\n        ]\n        results: List[int] = [f.result() for f in futures]\n    print(f\"Computed results: {results}\")\n\nif __name__ == '__main__':\n    main()","lang":"python","description":"This quickstart demonstrates using `concurrent.futures.ThreadPoolExecutor` with type hints. By installing `types-futures`, type checkers will correctly interpret the types of `Future` objects and executor methods, allowing for static analysis of your concurrent code."},"warnings":[{"fix":"Ensure you are installing `types-futures` for type-checking `concurrent.futures` in Python 3 environments, and do not install the `futures` runtime package on Python 3.","message":"Do not confuse `types-futures` with the `futures` PyPI package. The `futures` package is a Python 2 backport of `concurrent.futures` and is not compatible with Python 3. `types-futures` provides stubs for Python 3's built-in `concurrent.futures` module.","severity":"gotcha","affected_versions":"<=3.4.0 of `futures` PyPI package (runtime)"},{"fix":"Pin the `types-futures` version to match the major.minor version of the `concurrent.futures` (implicitly, your Python runtime) it's stubbing, e.g., `types-futures~=3.x.y`. Regularly update and re-run type checks.","message":"As `types-futures` is part of Typeshed, any version bump can introduce changes to the stubs that might cause your code to fail type checking, even if the runtime behavior remains the same. This is inherent to the nature of stub files aligning with potentially evolving APIs.","severity":"breaking","affected_versions":"All versions"},{"fix":"Be mindful of the context (asynchronous vs. thread/process-based concurrency) and use the appropriate `Future` class. Ensure correct type hints are used for each to leverage `types-futures` effectively.","message":"The `asyncio.Future` and `concurrent.futures.Future` classes are distinct and incompatible. Code expecting one will not correctly process the other, leading to runtime errors or incorrect type checking. `asyncio.Future` instances are awaitable, whereas `concurrent.futures.Future` instances are not.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}