summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_dataclasses.py
Commit message (Collapse)AuthorAgeFilesLines
* [3.10] gh-102947: Improve traceback when calling `fields()` on a ↵Alex Waygood2023-03-231-0/+12
| | | | non-dataclass (#102948) (#102954)
* [3.10] gh-90104: avoid RecursionError on recursive dataclass field repr ↵Carl Meyer2023-01-061-0/+18
| | | | | | | | | (gh-100756) (GH-100785) Avoid RecursionError on recursive dataclass field repr (cherry picked from commit 0a7936a38f0bab1619ee9fe257880a51c9d839d5) Automerge-Triggered-By: GH:ericvsmith
* [3.10] gh-96151: Use a private name for passing builtins to dataclass. This ↵Miss Islington (bot)2022-10-311-0/+8
| | | | | | | | | | now allows for a field named BUILTIN (gh-98143) (gh-98899) gh-96151: Use a private name for passing builtins to dataclass. This now allows for a field named BUILTIN (gh-98143) (cherry picked from commit 29f98b46b77ee528477b9a7b335974b9682f7f14) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
* Fix typo in test_dataclasses.py (gh-95735)Miss Islington (bot)2022-08-061-2/+2
| | | | | | `dataclass` was called as a function when it was almost certainly intended to be a decorator. (cherry picked from commit 59e09efe888affe549e9249f188797c1325edecc) Co-authored-by: da-woods <dw-git@d-woods.co.uk>
* [3.10] gh-91330: Tests and docs for dataclass descriptor-typed fields ↵Łukasz Langa2022-07-051-0/+109
| | | | | | | | (GH-94424) (GH-94577) Co-authored-by: Erik De Bonte <erikd@microsoft.com> Co-authored-by: Łukasz Langa <lukasz@langa.pl> (cherry picked from commit 5f319308a820f49fec66fc3ade50bbaa9fe2105d)
* bpo-45663: Fix is_dataclass() for dataclasses which are subclasses of ↵Miss Islington (bot)2021-12-051-0/+12
| | | | | | | types.GenericAlias (GH-29294) (cherry picked from commit 446be166861b2f08f87f74018113dd98ca5fca02) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-45662: Fix the repr of InitVar with a type alias to the built-in class ↵Miss Islington (bot)2021-12-051-0/+4
| | | | | | | | (GH-29291) For example, InitVar[list[int]]. (cherry picked from commit 1fd4de5bddbbf2a97cdbac4d298c89e1156bdc6c) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* bpo-44649: Fix dataclasses(slots=True) with a field with a default, but ↵Miss Islington (bot)2021-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. (cherry picked from commit d3062f672c92855b7e9e962ad4bf1a67abd4589b) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* Added kw_only parameter to make_dataclasses. (GH-29679)Miss Islington (bot)2021-11-201-0/+11
| | | | | (cherry picked from commit f7638dd0f90b2afd9295ee179119f4a29859953a) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-45566: `test_frozen_pickle` checks all `pickle` protocols (GH-29150)Miss Islington (bot)2021-10-241-4/+17
| | | | | | | | Refs https://github.com/python/cpython/pull/29147 Automerge-Triggered-By: GH:ericvsmith (cherry picked from commit 07236d562e59c6650227be18fa6ffc66b18d4741) Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
* Fix dataclassses spelling (GH-28837) (GH-28841)Miss Islington (bot)2021-10-091-1/+1
| | | | | | | (cherry picked from commit 5b4a7675bcfc6368aff955f4a6231579718f5dad) Co-authored-by: Landon Yarrington <33426811+jly36963@users.noreply.github.com> Co-authored-by: Landon Yarrington <33426811+jly36963@users.noreply.github.com>
* [3.10] Fix typos in the Lib directory (GH-28775) (GH-28804)Christian Clauss2021-10-071-1/+1
| | | | | | | | Fix typos in the Lib directory as identified by codespell. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>. (cherry picked from commit 745c9d9dfc1ad6fdfdf1d07420c6273ff67fa5be) Co-authored-by: Christian Clauss <cclauss@me.com>
* bpo-45081: Fix __init__ method generation when inheriting from Protocol ↵Miss Islington (bot)2021-09-031-1/+21
| | | | | | | | (GH-28121) Co-authored-by: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> (cherry picked from commit 0635e201beaf52373f776ff32702795e38f43ae3) Co-authored-by: Yurii Karabas <1998uriyyo@gmail.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
|
* Add test cases for dataclasses. (#17909)Karthikeyan Singaravelan2020-01-091-0/+19
| | | | | | | | * Add test cases for dataclasses. * Add test for repr output of field. * Add test for ValueError to be raised when both default and default_factory are passed.
* bpo-34776: Fix dataclasses to support __future__ "annotations" mode (#9518)Yury Selivanov2019-12-091-0/+12
|
* bpo-38431: Fix __repr__ method of InitVar to work with typing objects. ↵Samuel Colvin2019-10-131-0/+2
| | | | | | (GH-16702)
* Unmark files as executable that can't actually be executed. (GH-15353)Greg Price2019-08-211-0/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | There are plenty of legitimate scripts in the tree that begin with a `#!`, but also a few that seem to be marked executable by mistake. Found them with this command -- it gets executable files known to Git, filters to the ones that don't start with a `#!`, and then unmarks them as executable: $ git ls-files --stage \ | perl -lane 'print $F[3] if (!/^100644/)' \ | while read f; do head -c2 "$f" | grep -qxF '#!' \ || chmod a-x "$f"; \ done Looking at the list by hand confirms that we didn't sweep up any files that should have the executable bit after all. In particular * The `.psd` files are images from Photoshop. * The `.bat` files sure look like things that can be run. But we have lots of other `.bat` files, and they don't have this bit set, so it must not be needed for them. Automerge-Triggered-By: @benjaminp
* bpo-37868: Improve is_dataclass for instances. (GH-15325)Eric V. Smith2019-08-201-0/+26
|
* Fix typos in docs, comments and test assert messages (#14872)Min ho Kim2019-07-211-3/+3
|
* bpo-33569 Preserve type information with dataclasses.InitVar (GH-8927)Augusto Hack2019-06-031-0/+6
|
* bpo-36766: Typos in docs and code comments (GH-13116)penguindustin2019-05-061-1/+1
|
* bpo-36678: Rename duplicate tests in test_dataclasses (GH-12899)Windson yang2019-04-221-15/+3
|
* bpo-35960: Fix dataclasses.field throwing away empty metadata. (GH-11815)Christopher Hunt2019-02-121-2/+12
|
* bpo-33947: dataclasses no longer can raise RecursionError in repr (GF9916)Srinivas Thatiparthy (శ్రీనివాస్ తాటిపర్తి)2018-10-191-0/+86
| | | The reprlib code was copied here instead of importing reprlib. I'm not sure if we really need to avoid the import, but since I expect dataclasses to be more common that reprlib, it seems wise. Plus, the code is small.
* bpo-34363: dataclasses.asdict() and .astuple() now handle fields which are ↵Eric V. Smith2018-09-141-0/+79
| | | | namedtuples. (GH-9151)
* bpo-34213: Allow dataclasses to work with a field named 'object'. (GH-8452)Vadim Pushtaev2018-08-121-0/+50
|
* bpo-34184: Fix running Lib/test/test_dataclasses.py as a script. (GH-8382)Serhiy Storchaka2018-07-231-5/+5
|
* bpo-33805: Improve error message of dataclasses.replace() (GH-7580)Dong-hee Na2018-06-231-0/+16
|
* bpo-33796: Ignore ClassVar for dataclasses.replace(). (GH-7488)Eric V. Smith2018-06-071-85/+120
|
* bpo-33536: Validate make_dataclass() field names. (GH-6906)Eric V. Smith2018-05-161-108/+165
|
* bpo-33453: Handle string type annotations in dataclasses. (GH-6768)Eric V. Smith2018-05-161-2/+151
|
* Clean up and enhance frozen dataclass tests. (GH-6380)Eric V. Smith2018-04-051-27/+38
| | | | | * Add a test for frozen with unhashable field value. * Improve a comment.
* Allow dynamic creation of generic dataclasses (GH-6319)Ivan Levkivskyi2018-03-311-1/+18
|
* bpo-33175: dataclasses should look up __set_name__ on class, not instance ↵Eric V. Smith2018-03-291-5/+34
| | | | (GH-6305)