{"id":9374,"library":"types-attrs","title":"types-attrs (Legacy Type Stubs for attrs)","description":"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.","status":"deprecated","version":"19.1.0","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed/tree/master/stubs/attrs","tags":["typing","type stubs","attrs","mypy","type checking","deprecated"],"install":[{"cmd":"pip install types-attrs","lang":"bash","label":"Install types-attrs (for older attrs versions)"}],"dependencies":[],"imports":[{"note":"Types are provided directly by the `attrs` library for versions >= 18.2.0. You do not import directly from `types-attrs`.","symbol":"define","correct":"from attrs import define"},{"note":"Similarly, `field` is imported directly from `attrs`.","symbol":"field","correct":"from attrs import field"}],"quickstart":{"code":"import attr\nfrom attrs import define, field\nfrom typing import List, ClassVar\n\n@define\nclass User:\n    id: int = field(validator=attr.validators.instance_of(int))\n    name: str = field(default='Guest')\n    emails: List[str] = field(factory=list)\n    \n    # Correct way to define a class variable with type annotation\n    CLASS_CONSTANT: ClassVar[str] = \"SHARED_VALUE\"\n\n# Instantiate the class, type checkers will use annotations from `attrs`\nuser = User(id=123, name='Alice', emails=['alice@example.com'])\nprint(user)","lang":"python","description":"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."},"warnings":[{"fix":"Uninstall `types-attrs` if your `attrs` version is 18.2.0 or newer: `pip uninstall types-attrs`.","message":"The `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.","severity":"breaking","affected_versions":"attrs >= 18.2.0"},{"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.","message":"If 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()`.","severity":"gotcha","affected_versions":"All versions of attrs using type annotations"},{"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.","message":"Defining 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.","severity":"gotcha","affected_versions":"All versions of attrs using type annotations"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Uninstall the `types-attrs` package: `pip uninstall types-attrs`. Modern versions of `attrs` provide their own type annotations.","cause":"This error occurs when both the `attrs` library (version 18.2.0 or newer with built-in types) and the `types-attrs` stub package are installed. Mypy sees two sources of type information for the `attrs` module.","error":"Mypy: error: Duplicate module 'attrs'"},{"fix":"Ensure the `attrs` library is installed (`pip install attrs`). If using older `attrs` where `types-attrs` was necessary, ensure both are installed. Verify your Mypy configuration to include your project's installed packages.","cause":"This error can occur if `attrs` is not installed, or if `types-attrs` was installed for an older `attrs` version but `attrs` itself is missing, or if Mypy is not configured to find installed packages.","error":"Mypy: error: Cannot find module named 'attrs'"},{"fix":"To make 'some_field_name' an `attrs` attribute, either define it using `some_field_name = field(type=str)` or, for modern `attrs`, use `@define(auto_attribs=True)` on the class and define it as `some_field_name: str`.","cause":"This typically happens when a field is declared with a type annotation but without `attrs.field()` (and `auto_attribs=True` is not set), making it a plain Python class attribute rather than an `attrs` managed attribute.","error":"AttributeError: 'MyClass' object has no attribute 'some_field_name'"}]}