{"id":10323,"library":"types-first","title":"Types-First (Typing Stubs for 'first' library)","description":"This package provides PEP 561 compatible type stubs for the `first` library. It enables static type checkers like MyPy to correctly analyze code that uses the `first` function, enhancing code quality and preventing type-related errors. The current version is 2.0.5.20260408, and it's released as part of the `typeshed` project, which updates periodically.","status":"active","version":"2.0.5.20260408","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","type-hints","mypy","typeshed"],"install":[{"cmd":"pip install types-first","lang":"bash","label":"Install type stubs"},{"cmd":"pip install first","lang":"bash","label":"Install runtime library (required)"}],"dependencies":[{"reason":"This package provides type stubs for the 'first' runtime library; it is not functional without 'first' itself.","package":"first","optional":false}],"imports":[{"note":"This stub package provides type hints for the `first` function from the `first` library. You do not directly import `types-first` in your code; its presence is detected by type checkers.","symbol":"first","correct":"from first import first"}],"quickstart":{"code":"from typing import List, Optional\nfrom first import first\n\ndef get_first_even(numbers: List[int]) -> Optional[int]:\n    \"\"\"Finds the first even number in a list using the 'first' library.\"\"\"\n    # MyPy will use types-first to understand 'first' returns Optional[int]\n    return first(numbers, key=lambda x: x % 2 == 0)\n\n# Example usage with type hints\ndata: List[int] = [1, 3, 4, 5, 6]\nresult: Optional[int] = get_first_even(data)\nprint(f\"First even number: {result}\") # Expected: 4\n\ndata_no_even: List[int] = [1, 3, 5]\nresult_no_even: Optional[int] = get_first_even(data_no_even)\nprint(f\"First even number (none found): {result_no_even}\") # Expected: None\n","lang":"python","description":"This quickstart demonstrates how to use the `first` function with type hints. Installing `types-first` allows static analysis tools like MyPy to verify the types, such as ensuring `get_first_even` correctly handles `Optional[int]`."},"warnings":[{"fix":"Always install both `first` and `types-first`: `pip install first types-first`.","message":"Installing `types-first` only provides static type information; it does not include the actual `first` runtime library. Your application will encounter a `ModuleNotFoundError` if `first` is used in code without `pip install first`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure both `first` and `types-first` are updated regularly. If encountering type errors, check the `typeshed` GitHub repository for the latest status or specific issues related to `first` stubs.","message":"Type stub versions can sometimes lag behind or become out of sync with the runtime library versions. This might lead to incorrect type checking or false positives/negatives from static analysis tools if the API of `first` changes without corresponding stub updates.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Do not attempt to import `types_first`. Continue to import the actual runtime library: `from first import first`.","message":"For stub packages, direct imports like `import types_first` are not used. The `types-first` package simply needs to be installed in the environment for type checkers to find it when processing imports of the `first` library.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install the type stub package: `pip install types-first`.","cause":"MyPy or another static type checker cannot find the type definitions for the 'first' library.","error":"error: Missing type stubs for \"first\""},{"fix":"Install the runtime library: `pip install first`.","cause":"The actual 'first' runtime library is not installed in your Python environment. `types-first` only provides type hints, not the executable code.","error":"ModuleNotFoundError: No module named 'first'"},{"fix":"Ensure both `first` and `types-first` are up-to-date and compatible. Try reinstalling both: `pip uninstall first types-first && pip install first types-first`. Check MyPy configuration for any exclusions or incorrect paths.","cause":"This usually indicates a conflict, a corrupted installation, or a version mismatch where MyPy cannot correctly interpret the 'first' module's structure, even with stubs installed.","error":"error: Module \"first\" has no attribute \"first\" (MyPy error)"}]}