summaryrefslogtreecommitdiffstats
path: root/Lib/dataclasses.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-118974: Add `decorator` argument to `make_dataclass` (gh-122723)Victorien2024-10-011-3/+3
| | | This is to allow the `dataclasses.make_dataclass` infrastructure to be used with another decorator that's compliant with `typing.dataclass_transform`. The new `decorator` argument to `dataclasses.make_dataclass` is `dataclasses.dataclass`, which used to be hard coded.
* gh-113878: Add `doc` parameter to `dataclasses.field` (gh-114051)sobolevn2024-09-271-17/+37
| | | If using `slots=True`, the `doc` parameter ends up in the `__slots__` dict. The `doc` parameter is also in the corresponding `Field` object.
* gh-90562: Support zero argument super with dataclasses when slots=True ↵Eric V. Smith2024-09-251-8/+49
| | | | | | (gh-124455) Co-authored-by: @wookie184 Co-authored-by: Carl Meyer <carl@oddbird.net>
* dataclasses: Avoid using private class (#124465)Jelle Zijlstra2024-09-241-4/+1
| | | | | | typing.get_origin() does what we need here, without reaching into typing internals. This shouldn't change any behavior (so I am going to skip news), but it sets a good example for other users introspecting typing objects.
* gh-123935: Fix typo in `_get_slots` in `dataclasses.py` (#123941)sobolevn2024-09-121-1/+1
|
* Fix typos in comments and test code (#122846)Xie Yanbo2024-08-121-1/+1
|
* gh-119180: Add `annotationlib` module to support PEP 649 (#119891)Jelle Zijlstra2024-07-231-1/+3
| | | Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-120417: Remove unused imports in the stdlib (#120420)Victor Stinner2024-06-121-2/+1
|
* gh-118033: Fix `__weakref__` not set for generic dataclasses (#118099)Nikita Sobolev2024-05-091-3/+10
|
* gh-109870: Dataclasses: batch up exec calls (gh-110851)Eric V. Smith2024-03-251-144/+182
| | | Instead of calling `exec()` once for each function added to a dataclass, only call `exec()` once per dataclass. This can lead to speed improvements of up to 20%.
* gh-116647: Fix recursive child in dataclasses (#116790)et-repositories2024-03-191-1/+3
|
* gh-105866: fix dataclass with slots=True, weakref_slot=True (#105870)Aviel Boag2024-03-191-1/+3
| | | | | Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru> Co-authored-by: Carl Meyer <carl@oddbird.net>
* gh-109653: Just import `recursive_repr` in `dataclasses` (gh-109822)Nikita Sobolev2024-03-051-23/+3
|
* gh-114087: Speed up dataclasses._asdict_inner (#114088)keithasaurus2024-01-181-45/+55
|
* gh-114198: Rename dataclass __replace__ argument to 'self' (gh-114251)Phillip Schanely2024-01-181-6/+6
| | | | This change renames the dataclass __replace__ method's first argument name from 'obj' to 'self'.
* gh-109409: Fix inheritance of frozen dataclass from non-frozen dataclass ↵Nikita Sobolev2023-10-121-4/+10
| | | | | | mixins (gh-109437) Fix inheritance of frozen dataclass from non-frozen dataclass mixins
* gh-110273: dataclasses.replace() now raise TypeError for all invalid ↵Serhiy Storchaka2023-10-041-5/+5
| | | | | | | arguments (GH-110274) dataclasses.replace() now raises TypeError instead of ValueError if specify keyword argument for a field declared with init=False or miss keyword argument for required InitVar field.
* gh-108751: Add copy.replace() function (GH-108752)Serhiy Storchaka2023-09-061-3/+6
| | | | | | | | | It creates a modified copy of an object by calling the object's __replace__() method. It is a generalization of dataclasses.replace(), named tuple's _replace() method and replace() methods in various classes, and supports all these stdlib classes.
* gh-107838: In dataclasses, improve error message when a non-default field ↵Eric V. Smith2023-08-101-3/+3
| | | | | follows a default field. (gh-107842) Add the name of the previous default argument field in an error message.
* Fix typo in comment (gh-107389)Tom Niget2023-07-281-1/+1
|
* Small speedup for dataclass __eq__ and __repr__ (#104904)Raymond Hettinger2023-05-301-8/+12
| | | | | Faster __repr__ with str.__add__ moved inside the f-string. For __eq__ comp;are field by field instead of building temporary tuples. Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* gh-103000: Optimise `dataclasses.asdict` for the common case (#104364)Alex Waygood2023-05-101-5/+12
| | | Co-authored-by: David Ellis <ducksual@gmail.com>
* gh-104035: Do not ignore user-defined `__{get,set}state__` in slotted frozen ↵Nikita Sobolev2023-05-011-2/+4
| | | | dataclasses (#104041)
* gh-103449: Fix a bug in dataclass docstring generation (#103454)Nikita Sobolev2023-04-171-2/+7
|
* gh-103000: Optimise dataclasses asdict/astuple for common types (#103005)David Ellis2023-04-101-2/+29
| | | | Co-authored-by: Carl Meyer <carl@oddbird.net> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* gh-98886: Fix issues with dataclass fields with special underscore names ↵Shantanu2023-03-251-10/+9
| | | | | | | | | | | | | (#102032) This commit prefixes `__dataclass` to several things in the locals dict: - Names like `_dflt_` (which cause trouble, see first test) - Names like `_type_` (not known to be able to cause trouble) - `_return_type` (not known to able to cause trouble) - `_HAS_DEFAULT_FACTORY` (which causes trouble, see second test) In addition, this removes `MISSING` from the locals dict. As far as I can tell, this wasn't needed even in the initial implementation of dataclasses.py (and tests on that version passed with it removed). This makes me wary :-) This is basically a continuation of #96151, where fixing this was welcomed in https://github.com/python/cpython/pull/98143#issuecomment-1280306360
* gh-103027: Update `dataclass.make_dataclass` docstring (gh-103028)Nikita Sobolev2023-03-251-2/+5
| | | * gh-103027: Update `dataclass.make_dataclass` docstring
* gh-102947: Improve traceback when calling `fields()` on a non-dataclass ↵Alex Waygood2023-03-231-1/+1
| | | | (#102948)
* gh-102069: Fix `__weakref__` descriptor generation for custom dataclasses ↵Nikita Sobolev2023-03-131-0/+3
| | | | (#102075)
* gh-98169 dataclasses.astuple support DefaultDict (#98170)T2023-03-131-9/+16
| | | Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
* gh-88071: Update docstrings of dataclass' astuple and asdict (#101806)Ilya V. Schurov2023-03-111-2/+2
| | | Update dataclasses.astuple and dataclasses.asdict docstrings to reflect that they deep copy objects in the field values.
* gh-102103: add `module` argument to `dataclasses.make_dataclass` (#102104)Nikita Sobolev2023-03-111-1/+14
|
* gh-102578: Optimise setting and deleting mutable attributes on non-dataclass ↵Xuehai Pan2023-03-111-6/+4
| | | | subclasses of frozen dataclasses (gh-102573)
* gh-102515: Remove unused imports in the `Lib/` directory (#102516)Alex Waygood2023-03-081-1/+0
|
* gh-90104: avoid RecursionError on recursive dataclass field repr (gh-100756)Carl Meyer2023-01-061-21/+21
| | | Avoid RecursionError on recursive dataclass field repr
* gh-96151: Use a private name for passing builtins to dataclass. This now ↵Shantanu2022-10-311-5/+4
| | | | allows for a field named BUILTIN (gh-98143)
* bpo-35540 dataclasses.asdict now supports defaultdict fields (gh-32056)Tiger2022-10-071-0/+8
|
* gh-96142: add missing params to `dataclass._DataclassParams` (gh-96382)Nikita Sobolev2022-10-041-3/+19
|
* Add comment to subtle dataclass code (gh-96133)Shantanu2022-10-041-0/+4
| | | | | | | | | In the PR that made this change, 1st1 left a "note to self: add a comment explaining this". This comment was never added. https://github.com/python/cpython/pull/9518/files#r280608117 I was reading this code and it wasn't obvious to me why we weren't exec-ing directly into locals. So I got to learn something new :-) https://docs.python.org/3/reference/executionmodel.html#interaction-with-dynamic-features
* gh-97799: use inspect.get_annotations in dataclass (#97800)larryhastings2022-10-031-5/+2
| | | | | | dataclass used to get the annotations on a class object using cls.__dict__.get('__annotations__'). Now that it always imports inspect, it can use inspect.get_annotations, which is modern best practice for coping with annotations.
* Fix minor docstring issues in `dataclasses.py`. (gh-93024)Roman Novak2022-07-261-7/+7
| | | Previously, when using `functools.wrap` around them (and inherit their docstrings), sphinx renders the docstrings badly and raises warnings about wrong indent.
* Improve dataclass docstring (gh-94686)Tom Fryers2022-07-091-9/+8
|
* gh-89828: Do not relay the __class__ attribute in GenericAlias (#93754)Serhiy Storchaka2022-06-181-2/+2
| | | | | list[int].__class__ returned type, and isinstance(list[int], type) returned True. It caused numerous problems in code that checks isinstance(x, type).
* GH-93521: For dataclasses, filter out `__weakref__` slot if present in bases ↵Bluenix2022-06-081-4/+9
| | | | (GH-93535)
* Add weakref_slot to dataclass decorator, to allow instances with slots to be ↵Eric V. Smith2022-05-021-8/+19
| | | | weakref-able. (#92160)
* bpo-47126: Update to canonical PEP URLs specified by PEP 676 (GH-32124)Hugo van Kemenade2022-03-301-1/+1
|
* bpo-46382 dataclass(slots=True) now takes inherited slots into account ↵Arie Bovenberg2022-03-191-1/+22
| | | | | (GH-31980) Do not include any members in __slots__ that are already in a base class's __slots__.
* bpo-44674: Use unhashability as a proxy for mutability for default dataclass ↵Eric V. Smith2021-12-111-2/+4
| | | | | __init__ arguments. (GH-29867) `@dataclass` in 3.10 prohibits using list, dict, or set as default values. It does this to avoid the mutable default problem. This test is both too strict, and not strict enough. Too strict, because some immutable subclasses should be safe, and not strict enough, because other mutable types should be prohibited. With this change applied, `@dataclass` now uses unhashability as a proxy for mutability: if objects aren't hashable, they're assumed to be mutable.
* bpo-45663: Fix is_dataclass() for dataclasses which are subclasses of ↵Serhiy Storchaka2021-12-051-1/+1
| | | | types.GenericAlias (GH-29294)
* bpo-45662: Fix the repr of InitVar with a type alias to the built-in class ↵Serhiy Storchaka2021-12-051-1/+1
| | | | | (GH-29291) For example, InitVar[list[int]].