summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dataclasses.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-108303: Create Lib/test/test_dataclasses/ directory (#108978)Victor Stinner2023-09-061-4547/+0
| | | | Move test_dataclasses.py and its "dataclass_*.py" modules into the new Lib/test/test_dataclasses/ subdirectory.
* gh-107838: In dataclasses, improve error message when a non-default field ↵Eric V. Smith2023-08-101-4/+4
| | | | | follows a default field. (gh-107842) Add the name of the previous default argument field in an error message.
* gh-104035: Do not ignore user-defined `__{get,set}state__` in slotted frozen ↵Nikita Sobolev2023-05-011-0/+68
| | | | dataclasses (#104041)
* gh-104015: Fix direct invocation of `test_dataclasses` (#104017)Nikita Sobolev2023-04-301-1/+1
| | | Previously, `python -m test test_dataclasses` passed, but `./python.exe Lib/test/test_dataclasses.py` failed
* GH-103805: Lib test f541 linting issue fix (#103812)Rodolfo M. Pereira2023-04-241-2/+2
| | | | | | | | | | | | | | | | This PR makes some minor linting adjustments to the Lib/test module caught by [ruff](https://github.com/charliermarsh/ruff). The adjustments are all related to the `F541 f-string without any placeholders` issue. Issue: https://github.com/python/cpython/issues/103805 <!-- gh-issue-number: gh-103805 --> * Issue: gh-103805 <!-- /gh-issue-number --> --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
* gh-103449: Fix a bug in dataclass docstring generation (#103454)Nikita Sobolev2023-04-171-0/+13
|
* gh-98886: Fix issues with dataclass fields with special underscore names ↵Shantanu2023-03-251-0/+17
| | | | | | | | | | | | | (#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-102947: Improve traceback when calling `fields()` on a non-dataclass ↵Alex Waygood2023-03-231-0/+12
| | | | (#102948)
* gh-102069: Fix `__weakref__` descriptor generation for custom dataclasses ↵Nikita Sobolev2023-03-131-4/+11
| | | | (#102075)
* gh-98169 dataclasses.astuple support DefaultDict (#98170)T2023-03-131-4/+17
| | | Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
* gh-102103: add `module` argument to `dataclasses.make_dataclass` (#102104)Nikita Sobolev2023-03-111-0/+39
|
* gh-102578: Optimise setting and deleting mutable attributes on non-dataclass ↵Xuehai Pan2023-03-111-0/+44
| | | | 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-0/+18
| | | Avoid RecursionError on recursive dataclass field repr
* gh-98284: better error message for undefined abstractmethod (#97971)Kaushik Kulkarni2022-11-051-1/+1
|
* gh-96151: Use a private name for passing builtins to dataclass. This now ↵Shantanu2022-10-311-0/+8
| | | | allows for a field named BUILTIN (gh-98143)
* bpo-35540 dataclasses.asdict now supports defaultdict fields (gh-32056)Tiger2022-10-071-2/+19
|
* gh-96142: add missing params to `dataclass._DataclassParams` (gh-96382)Nikita Sobolev2022-10-041-0/+26
|
* Fix typo in test_dataclasses.py (gh-95735)da-woods2022-08-061-2/+2
| | | `dataclass` was called as a function when it was almost certainly intended to be a decorator.
* gh-91330: Tests and docs for dataclass descriptor-typed fields (GH-94424)Erik De Bonte2022-07-051-0/+109
| | | Co-authored-by: Łukasz Langa <lukasz@langa.pl>
* GH-93521: For dataclasses, filter out `__weakref__` slot if present in bases ↵Bluenix2022-06-081-0/+48
| | | | (GH-93535)
* gh-91578: improved error message when trying to instantiate an abstract ↵ravi1402222022-05-121-1/+1
| | | | class with missing methods (gh-47246)
* Add weakref_slot to dataclass decorator, to allow instances with slots to be ↵Eric V. Smith2022-05-021-0/+72
| | | | weakref-able. (#92160)
* bpo-46382 dataclass(slots=True) now takes inherited slots into account ↵Arie Bovenberg2022-03-191-8/+43
| | | | | (GH-31980) Do not include any members in __slots__ that are already in a base class's __slots__.
* bpo-46757: Add a test to verify dataclass's __post_init__ isn't being ↵Eric V. Smith2022-02-231-0/+59
| | | | automatically added. (GH-31523)
* bpo-44674: Use unhashability as a proxy for mutability for default dataclass ↵Eric V. Smith2021-12-111-0/+26
| | | | | __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-0/+12
| | | | types.GenericAlias (GH-29294)
* bpo-45662: Fix the repr of InitVar with a type alias to the built-in class ↵Serhiy Storchaka2021-12-051-0/+4
| | | | | (GH-29291) For example, InitVar[list[int]].
* bpo-44649: Fix dataclasses(slots=True) with a field with a default, but ↵Eric V. Smith2021-11-221-0/+22
| | | | | init=False (GH-29692) Special handling is needed, because for non-slots dataclasses the instance attributes are not set: reading from a field just references the class's attribute of the same name, which contains the default value. But this doesn't work for classes using __slots__: they don't read the class's attribute. So in that case (and that case only), initialize the instance attribute. Handle this for both normal defaults, and for fields using default_factory.
* Added kw_only parameter to make_dataclasses. (GH-29679)Eric V. Smith2021-11-201-0/+11
|
* bpo-45566: `test_frozen_pickle` checks all `pickle` protocols (GH-29150)Nikita Sobolev2021-10-241-4/+17
| | | | | Refs https://github.com/python/cpython/pull/29147 Automerge-Triggered-By: GH:ericvsmith
* Fix dataclassses spelling (GH-28837)Landon Yarrington2021-10-091-1/+1
|
* Fix typos in the Lib directory (GH-28775)Christian Clauss2021-10-061-1/+1
| | | | | Fix typos in the Lib directory as identified by codespell. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
* bpo-45081: Fix __init__ method generation when inheriting from Protocol ↵Yurii Karabas2021-09-021-1/+21
| | | | | (GH-28121) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com>
* bpo-44015: dataclasses should allow KW_ONLY to be specified only once per ↵Eric V. Smith2021-05-031-0/+77
| | | | | class (GH-25841) bpo-44015: Raise a TypeError if KW_ONLY is specified more than once.
* If using a frozen class with slots, add __getstate__ and __setstate__ to set ↵Eric V. Smith2021-05-011-0/+13
| | | | the instance values. (GH-25786)
* bpo-42269: Add slots parameter to dataclass decorator (GH-24171)Yurii Karabas2021-05-011-0/+53
| | | Add slots parameter to dataclass decorator and make_dataclass function.
* Add additional keyword-only tests. (GH-25633)Eric V. Smith2021-04-261-1/+29
|
* Add keyword-only fields to dataclasses. (GH=25608)Eric V. Smith2021-04-261-0/+159
|
* bpo-38605: Revert making 'from __future__ import annotations' the default ↵Pablo Galindo2021-04-211-29/+48
| | | | | | (GH-25490) This reverts commits 044a1048ca93d466965afc027b91a5a9eb9ce23c and 1be456ae9d53bb1cba2b24fc86175c282d1c2169, adapting the code to changes that happened after it.
* bpo-43764: Add match_args=False parameter to dataclass decorator and to ↵Eric V. Smith2021-04-111-0/+41
| | | | | make_dataclasses function. (GH-25337) Add match_args=False parameter to dataclass decorator and to make_dataclass function.
* bpo-43764: Fix `__match_args__` generation logic for dataclasses (GH-25284)Brandt Bucher2021-04-081-0/+8
|
* bpo-43176: Fix processing of empty dataclasses (GH-24484)Iurii Kemaev2021-04-061-0/+24
| | | | | When a dataclass inherits from an empty base, all immutability checks are omitted. This PR fixes this and adds tests for it. Automerge-Triggered-By: GH:ericvsmith
* bpo-42128: __match_args__ can't be a list anymore (GH-25203)Brandt Bucher2021-04-061-1/+1
|
* bpo-36470: Allow dataclasses.replace() to handle InitVars with default ↵Zackery Spytz2021-04-051-0/+18
| | | | | | | values (GH-20867) Co-Authored-By: Claudiu Popa <pcmanticore@gmail.com> Automerge-Triggered-By: GH:ericvsmith
* bpo-42128: Structural Pattern Matching (PEP 634) (GH-22917)Brandt Bucher2021-02-261-0/+16
| | | | | Co-authored-by: Guido van Rossum <guido@python.org> Co-authored-by: Talin <viridia@gmail.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* bpo-41747: Ensure all dataclass methods uses their parents' qualname (GH-22155)Batuhan Taskaya2020-10-211-0/+24
| | | | | * bpo-41747: Ensure all dataclass methods uses their parents' qualname Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-38605: Make 'from __future__ import annotations' the default (GH-20434)Batuhan Taskaya2020-10-061-49/+30
| | | | | The hard part was making all the tests pass; there are some subtle issues here, because apparently the future import wasn't tested very thoroughly in previous Python versions. For example, `inspect.signature()` returned type objects normally (except for forward references), but strings with the future import. We changed it to try and return type objects by calling `typing.get_type_hints()`, but fall back on returning strings if that function fails (which it may do if there are future references in the annotations that require passing in a specific namespace to resolve).
* bpo-41905: Add abc.update_abstractmethods() (GH-22485)Ben Avrahami2020-10-061-0/+37
| | | | This function recomputes `cls.__abstractmethods__`. Also update `@dataclass` to use it.
* bpo-40389: Improve repr of typing.Optional (#19714)Vlad Serebrennikov2020-04-301-1/+1
|