{
    "mode": "pydoc",
    "parameter": "dataclasses",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/dataclasses/json",
    "generated": "2026-06-02T15:03:24Z",
    "sections": {
        "NAME": {
            "content": "dataclasses\n",
            "subsections": []
        },
        "MODULE REFERENCE": {
            "content": "https://docs.python.org/3.10/library/dataclasses.html\n\nThe following documentation is automatically generated from the Python\nsource files.  It may be incomplete, incorrect or include features that\nare considered implementation detail and may vary between Python\nimplementations.  When in doubt, consult the module reference at the\nlocation listed above.\n",
            "subsections": []
        },
        "CLASSES": {
            "content": "builtins.AttributeError(builtins.Exception)\nFrozenInstanceError\nbuiltins.object\nField\nInitVar\n",
            "subsections": [
                {
                    "name": "class Field",
                    "content": "|  Field(default, defaultfactory, init, repr, hash, compare, metadata, kwonly)\n|\n|  # Instances of Field are only ever created from within this module,\n|  # and only from the field() function, although Field instances are\n|  # exposed externally as (conceptually) read-only objects.\n|  #\n|  # name and type are filled in after the fact, not in init.\n|  # They're not known at the time this class is instantiated, but it's\n|  # convenient if they're available later.\n|  #\n|  # When cls.FIELDS is filled in with a list of Field objects, the name\n|  # and type fields will have been populated.\n|\n|  Methods defined here:\n|\n|  init(self, default, defaultfactory, init, repr, hash, compare, metadata, kwonly)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  repr(self)\n|      Return repr(self).\n|\n|  setname(self, owner, name)\n|      # This is used to support the PEP 487 setname protocol in the\n|      # case where we're using a field that contains a descriptor as a\n|      # default value.  For details on setname, see\n|      # https://www.python.org/dev/peps/pep-0487/#implementation-details.\n|      #\n|      # Note that in processclass, this Field object is overwritten\n|      # with the default value, so the end result is a descriptor that\n|      # had setname called on it at the right time.\n|\n|  ----------------------------------------------------------------------\n|  Class methods defined here:\n|\n|  classgetitem = GenericAlias(...) from builtins.type\n|      Represent a PEP 585 generic type\n|\n|      E.g. for t = list[int], t.origin is list and t.args is (int,).\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  compare\n|\n|  default\n|\n|  defaultfactory\n|\n|  hash\n|\n|  init\n|\n|  kwonly\n|\n|  metadata\n|\n|  name\n|\n|  repr\n|\n|  type\n"
                },
                {
                    "name": "class FrozenInstanceError",
                    "content": "|  # Raised when an attempt is made to modify a frozen class.\n|\n|  Method resolution order:\n|      FrozenInstanceError\n|      builtins.AttributeError\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Data descriptors defined here:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.AttributeError:\n|\n|  init(self, /, *args, kwargs)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  str(self, /)\n|      Return str(self).\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.AttributeError:\n|\n|  name\n|      attribute name\n|\n|  obj\n|      object\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.Exception:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  reduce(...)\n|      Helper for pickle.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n"
                },
                {
                    "name": "class InitVar",
                    "content": "|  InitVar(type)\n|\n|  Methods defined here:\n|\n|  init(self, type)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  repr(self)\n|      Return repr(self).\n|\n|  ----------------------------------------------------------------------\n|  Class methods defined here:\n|\n|  classgetitem(type) from builtins.type\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  type\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "asdict",
                    "content": "Return the fields of a dataclass instance as a new dictionary mapping\nfield names to field values.\n\nExample usage:\n\n@dataclass\nclass C:\nx: int\ny: int\n\nc = C(1, 2)\nassert asdict(c) == {'x': 1, 'y': 2}\n\nIf given, 'dictfactory' will be used instead of built-in dict.\nThe function applies recursively to field values that are\ndataclass instances. This will also look into built-in containers:\ntuples, lists, and dicts.\n"
                },
                {
                    "name": "astuple",
                    "content": "Return the fields of a dataclass instance as a new tuple of field values.\n\nExample usage::\n\n@dataclass\nclass C:\nx: int\ny: int\n\nc = C(1, 2)\nassert astuple(c) == (1, 2)\n\nIf given, 'tuplefactory' will be used instead of built-in tuple.\nThe function applies recursively to field values that are\ndataclass instances. This will also look into built-in containers:\ntuples, lists, and dicts.\n"
                },
                {
                    "name": "dataclass",
                    "content": "Returns the same class as was passed in, with dunder methods\nadded based on the fields defined in the class.\n\nExamines PEP 526 annotations to determine fields.\n\nIf init is true, an init() method is added to the class. If\nrepr is true, a repr() method is added. If order is true, rich\ncomparison dunder methods are added. If unsafehash is true, a\nhash() method function is added. If frozen is true, fields may\nnot be assigned to after instance creation. If matchargs is true,\nthe matchargs tuple is added. If kwonly is true, then by\ndefault all fields are keyword-only. If slots is true, an\nslots attribute is added.\n"
                },
                {
                    "name": "field",
                    "content": "Return an object to identify dataclass fields.\n\ndefault is the default value of the field.  defaultfactory is a\n0-argument function called to initialize a field's value.  If init\nis true, the field will be a parameter to the class's init()\nfunction.  If repr is true, the field will be included in the\nobject's repr().  If hash is true, the field will be included in the\nobject's hash().  If compare is true, the field will be used in\ncomparison functions.  metadata, if specified, must be a mapping\nwhich is stored but not otherwise examined by dataclass.  If kwonly\nis true, the field will become a keyword-only parameter to\ninit().\n\nIt is an error to specify both default and defaultfactory.\n"
                },
                {
                    "name": "fields",
                    "content": "Return a tuple describing the fields of this dataclass.\n\nAccepts a dataclass or an instance of one. Tuple elements are of\ntype Field.\n"
                },
                {
                    "name": "is_dataclass",
                    "content": "Returns True if obj is a dataclass or an instance of a\ndataclass.\n"
                },
                {
                    "name": "make_dataclass",
                    "content": "Return a new dynamically created dataclass.\n\nThe dataclass name will be 'clsname'.  'fields' is an iterable\nof either (name), (name, type) or (name, type, Field) objects. If type is\nomitted, use the string 'typing.Any'.  Field objects are created by\nthe equivalent of calling 'field(name, type [, Field-info])'.\n\nC = makedataclass('C', ['x', ('y', int), ('z', int, field(init=False))], bases=(Base,))\n\nis equivalent to:\n\n@dataclass\nclass C(Base):\nx: 'typing.Any'\ny: int\nz: int = field(init=False)\n\nFor the bases and namespace parameters, see the builtin type() function.\n\nThe parameters init, repr, eq, order, unsafehash, and frozen are passed to\ndataclass().\n"
                },
                {
                    "name": "replace",
                    "content": "Return a new object replacing specified fields with new values.\n\nThis is especially useful for frozen classes.  Example usage:\n\n@dataclass(frozen=True)\nclass C:\nx: int\ny: int\n\nc = C(1, 2)\nc1 = replace(c, x=3)\nassert c1.x == 3 and c1.y == 2\n"
                }
            ]
        },
        "DATA": {
            "content": "KWONLY = <dataclasses.KWONLYTYPE object>\nMISSING = <dataclasses.MISSINGTYPE object>\nall = ['dataclass', 'field', 'Field', 'FrozenInstanceError', 'Init...\n",
            "subsections": []
        },
        "FILE": {
            "content": "/usr/lib/python3.10/dataclasses.py\n\n",
            "subsections": []
        }
    },
    "summary": "dataclasses",
    "flags": [],
    "examples": [],
    "see_also": []
}