Types-First (Typing Stubs for 'first' library)

2.0.5.20260408 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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]`.

from typing import List, Optional
from first import first

def get_first_even(numbers: List[int]) -> Optional[int]:
    """Finds the first even number in a list using the 'first' library."""
    # MyPy will use types-first to understand 'first' returns Optional[int]
    return first(numbers, key=lambda x: x % 2 == 0)

# Example usage with type hints
data: List[int] = [1, 3, 4, 5, 6]
result: Optional[int] = get_first_even(data)
print(f"First even number: {result}") # Expected: 4

data_no_even: List[int] = [1, 3, 5]
result_no_even: Optional[int] = get_first_even(data_no_even)
print(f"First even number (none found): {result_no_even}") # Expected: None

view raw JSON →