types-attrs (Legacy Type Stubs for attrs)

19.1.0 · deprecated · verified Thu Apr 16

types-attrs provides PEP 561 type stubs for the attrs library. However, the attrs library itself has included robust type annotations since version 18.2.0. Consequently, `types-attrs` is largely obsolete and should be uninstalled if you are using attrs version 18.2.0 or newer. It is an auto-generated package from the Python 'typeshed' repository and is considered deprecated for modern `attrs` usage.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates defining an `attrs` class with type annotations. Note that `types-attrs` is not imported, as the `attrs` library (version 18.2.0 and newer) provides its own type information directly. Type checkers like Mypy will pick up types from the `attrs` package itself.

import attr
from attrs import define, field
from typing import List, ClassVar

@define
class User:
    id: int = field(validator=attr.validators.instance_of(int))
    name: str = field(default='Guest')
    emails: List[str] = field(factory=list)
    
    # Correct way to define a class variable with type annotation
    CLASS_CONSTANT: ClassVar[str] = "SHARED_VALUE"

# Instantiate the class, type checkers will use annotations from `attrs`
user = User(id=123, name='Alice', emails=['alice@example.com'])
print(user)

view raw JSON →