Typing Stubs for Dataclasses

0.6.6 · deprecated · verified Sun Apr 12

This package provides PEP 561 compliant type stubs for the standard library's `dataclasses` module. It enables static type checkers like MyPy, PyCharm, or pytype to correctly analyze code that utilizes dataclasses by providing type definitions. The current version is 0.6.6. It is important to note that this specific `types-dataclasses` package is unmaintained and will not receive further updates; all fixes and contributions for `dataclasses` stubs are now managed directly within the `typeshed` project.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the standard usage of `dataclasses` with type hints. The `types-dataclasses` package provides the necessary type definitions for static analysis tools to correctly validate such code. No direct import from `types_dataclasses` is required in user code.

from dataclasses import dataclass
from typing import List

@dataclass
class Point:
    x: int
    y: int

@dataclass
class TaggedItem:
    name: str
    tags: List[str]

def process_point(p: Point):
    print(f"Processing point: ({p.x}, {p.y})")

p = Point(10, 20)
process_point(p)

item = TaggedItem(name="Book", tags=["fiction", "novel"])
print(f"Item: {item.name}, Tags: {', '.join(item.tags)}")

view raw JSON →