Registry / type-stubs / types-attrs

types-attrs

JSON →
library19.1.0pypypiunverified

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.

pip install types-attrs
INSTALL
IMPORT
SIG · TYPES-ATTRS
T
types-attrs
type-stubspythonv19.1.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v19.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

define
from attrs import define
from attr import define

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)
Debug
Known issues
breakingThe `types-attrs` package is obsolete for `attrs` versions 18.2.0 and newer. The `attrs` library itself ships with type annotations, making this stub package redundant and potentially problematic if both are installed.
fix
Uninstall `types-attrs` if your `attrs` version is 18.2.0 or newer: `pip uninstall types-attrs`.
affects: attrs >= 18.2.0
gotchaIf you define a class with an `attrs.field()` that lacks a type annotation, `attrs` will ignore other fields that *do* have a type annotation but are *not* defined using `attrs.field()`.
fix
Always annotate all attributes if you use type annotations. For fields needing advanced `attrs` features (like validators, converters, or factories), use `attrs.field()` in conjunction with type annotations. For simple attributes, `attrs.define(auto_attribs=True)` allows omitting `field()` if all attributes are type-annotated.
affects: All versions of attrs using type annotations
gotchaDefining an attribute with only a type annotation (e.g., `x: int = 10`) without `attrs.field()` does not make it an `attrs` attribute if other fields use `attrs.field()`. Such attributes will not participate in `attrs` features like `__init__`, `__repr__`, etc.
fix
Either use `attrs.field()` for all attributes, or enable `auto_attribs=True` on the `@define` decorator and ensure *all* attributes are type-annotated to have `attrs` manage them. Use `typing.ClassVar` for true class-level variables that should not be part of the `attrs` instance.
affects: All versions of attrs using type annotations
Upgrade
Version history
19.1.0latest on PyPI · released Jun 6, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
types-attrs — pip install types-attrs · libregistry