summaryrefslogtreecommitdiffstats
path: root/Lib/dataclasses.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-34776: Fix dataclasses to support __future__ "annotations" mode ↵Miss Islington (bot)2019-12-091-34/+53
| | | | | | | (GH-9518) (#17532) (cherry picked from commit d219cc4180e7589807ebbef7421879f095e72a98) Co-authored-by: Yury Selivanov <yury@magic.io>
* bpo-37868: Improve is_dataclass for instances. (GH-15325)Miss Islington (bot)2019-08-201-2/+3
| | | | | (cherry picked from commit b0f4dab8735f692bcfedcf0fa9a25e238a554bab) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* [3.7] Fix typos in docs, comments and test assert messages (GH-14872). (#14901)Kyle Stanley2019-07-221-1/+1
| | | | | (cherry picked from commit 96e12d5f4f3c5a20986566038ee763dff3c228a1) Co-authored-by: Min ho Kim <minho42@gmail.com>
* [3.7] bpo-37163: dataclasses.replace() now supports the field named "obj". ↵Serhiy Storchaka2019-06-261-1/+9
| | | | | | (GH-13877) (GH-14405) (cherry picked from commit f5b89af)
* bpo-35960: Fix dataclasses.field throwing away empty metadata. (GH-11815) ↵Miss Islington (bot)2019-02-121-1/+1
| | | | | | | (GH-11826) (cherry picked from commit b01786c8812c4cc24dd561b5941025bdd6f444c0) Co-authored-by: Christopher Hunt <chrahunt@gmail.com>
* bpo-33947: dataclasses no longer can raise RecursionError in repr (GF9916) ↵Miss Islington (bot)2018-10-191-6/+31
| | | | | | | | (#9970) 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. (cherry picked from commit dd13c88b5371e13fc16b84e2f9b8715d917de269) Co-authored-by: Srinivas Thatiparthy (శ్రీనివాస్ తాటిపర్తి) <srinivasreddy@users.noreply.github.com>
* bpo-34363: dataclasses.asdict() and .astuple() now handle fields which are ↵Miss Islington (bot)2018-09-141-2/+38
| | | | | | | namedtuples. (GH-9151) (GH-9304) (cherry picked from commit 9b9d97dd139a799d28ff8bc90d118b1cac190b03) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-34213: Allow dataclasses to work with a field named 'object'. (GH-8452)Miss Islington (bot)2018-08-131-1/+7
| | | | | (cherry picked from commit 4d12e4dc28b7c782c368bae2e8fd3815167ed37d) Co-authored-by: Vadim Pushtaev <pushtaev.vm@gmail.com>
* Fix typo in dataclasses documentation (GH-8102)Miss Islington (bot)2018-07-051-1/+1
| | | | | (cherry picked from commit e55ca3fdcbb8dda04f6f9fb2ccd1069aa1100cd5) Co-authored-by: Artjom <tjomk@users.noreply.github.com>
* bpo-33805: Improve error message of dataclasses.replace() (GH-7580)Miss Islington (bot)2018-06-231-0/+3
| | | | | (cherry picked from commit 3d70f7aef614c396f516b5fccedeebe98598714d) Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
* bpo-33796: Ignore ClassVar for dataclasses.replace(). (GH-7488)Miss Islington (bot)2018-06-071-1/+5
| | | | | (cherry picked from commit e7adf2ba41832404100313f9ac9d9f7fabedc1fd) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-33536: Validate make_dataclass() field names. (GH-6906)Miss Islington (bot)2018-05-161-0/+15
| | | | | (cherry picked from commit 4e81296b1874829912c687eba4d39361ab51e145) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-33534: Remove unneeded test. (GH-6897)Miss Islington (bot)2018-05-161-6/+5
| | | | | | This condition as already tested before this code is called. (cherry picked from commit 9285835a05ad0319acef111340266c0f85ed549c) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* Reflow dataclasses comments (GH-6893)Miss Islington (bot)2018-05-161-170/+176
| | | | | | To be more consistent with other code (and so people stop hassling me!), reflow the dataclasses comments to not use a single space indentation when continuing a paragraph of text. (cherry picked from commit f8e7549490d61c92b34bf2de3e03ba2f7b0ac6e1) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-33453: Handle string type annotations in dataclasses. (GH-6768)Miss Islington (bot)2018-05-161-18/+116
| | | | | (cherry picked from commit 2a7bacbd913cf2bf568b3c0f85a758946d3cf4e9) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-33517: dataclasses: Add the field type to Field repr (GH-6858)Miss Islington (bot)2018-05-151-4/+10
| | | | | (cherry picked from commit 01abc6ec3a61769c55ee86834a432fb97801d28f) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-33502: dataclass._Dataclassparams repr: use repr of each member. (GH-6812)Miss Islington (bot)2018-05-141-6/+6
| | | | | (cherry picked from commit 3059042410dce69806b94be72d5c8055d616f3a3) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-33494: Change dataclasses.Fields repr to use the repr of each of its ↵Miss Islington (bot)2018-05-141-8/+8
| | | | | | | members (GH-6798) (cherry picked from commit 2473eea65d592a80a5362a00362738a33196aba1) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* Allow dynamic creation of generic dataclasses (GH-6319) (GH-6320)Miss Islington (bot)2018-04-011-1/+3
| | | | | (cherry picked from commit 5a7092de1226a95a50f0f384eea8ddb288959249) Co-authored-by: Ivan Levkivskyi <levkivskyi@gmail.com>
* bpo-33175: dataclasses should look up __set_name__ on class, not instance ↵Miss Islington (bot)2018-03-291-2/+2
| | | | | | | (GH-6305) (cherry picked from commit 521995205a2cb6b504fe0e39af22a81f785350a3) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-33141: Have dataclasses.Field pass through __set_name__ to any default ↵Miss Islington (bot)2018-03-261-0/+14
| | | | | | | | argument. (GH-6260) This is part of PEP 487 and the descriptor protocol. (cherry picked from commit de7a2f04d6b9427d568fcb43b6f512f9b4c4bd84) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-33134: dataclasses: use function dispatch table for hash, instead of a ↵Miss Islington (bot)2018-03-251-40/+36
| | | | | | | | | string lookup which then is tested with if tests. (GH-6222) * Change _hash_action to be a function table lookup, instead of a list of strings which is then tested with if statements. (cherry picked from commit 01d618c5606a239b03ad1269541eddb6e724775d) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* Trivial dataclass cleanups: (GH-6218)Miss Islington (bot)2018-03-241-23/+26
| | | | | | | | | | | | | - When adding a single element to a list, use .append() instead of += and creating a new list. - For consistency, import the copy module, instead of just deepcopy. This leaves only a module at the class level, instead of a function. - Improve some comments. - Improve some whitespace. - Use tuples instead of lists. - Simplify a test. (cherry picked from commit f96ddade0094d162cb6c2fd7255c5e8a90b5c37d) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-32505: dataclasses: raise TypeError if a member variable is of type ↵Miss Islington (bot)2018-03-221-17/+21
| | | | | | | | Field, but doesn't have a type annotation. (GH-6192) If a dataclass has a member variable that's of type Field, but it doesn't have a type annotation, raise TypeError. (cherry picked from commit 56970b8ce9d23269d20a76f13c80e670c856ba7f) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-33116: Add 'Field' to dataclasses.__all__. (GH-6182) (GH-6183)Miss Islington (bot)2018-03-211-1/+2
| | | | | | | - Add missing 'Field' to __all__. - Improve tests to catch this. (cherry picked from commit 8e4560a9da6a02aa157dd7df8bd0be0d258c0a73) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-32896: Fix error when subclassing a dataclass with a field that uses a ↵Miss Islington (bot)2018-03-211-11/+12
| | | | | | | | default_factory (GH-6170) (GH-6171) Fix the way that new annotations in a class are detected. (cherry picked from commit 8f6eccdc64cab735c47620fea948e64b19f83684) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-33100: Dataclasses now handles __slots__ and default values correctly. ↵Miss Islington (bot)2018-03-201-0/+3
| | | | | | | | (GH-6152) (GH-6153) If the class has a member that's a MemberDescriptorType, it's not a default value, it's from that member being in __slots__. (cherry picked from commit 7389fd935c95b4b6f094312294e703ee0de18719) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-32953: Dataclasses: frozen should not be inherited for non-dataclass ↵Miss Islington (bot)2018-03-191-31/+89
| | | | | | | | | | derived classes (GH-6147) (GH-6148) If a non-dataclass derives from a frozen dataclass, allow attributes to be set. Require either all of the dataclasses in a class hierarchy to be frozen, or all non-frozen. Store `@dataclass` parameters on the class object under `__dataclass_params__`. This is needed to detect frozen base classes. (cherry picked from commit f199bc655eb50c28e94010714629b376bbbd077b) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* Fixed incorrect default value for dataclass unsafe_hash. (GH-5949) (GH-5950)Miss Islington (bot)2018-03-011-2/+2
| | | | | (cherry picked from commit 5da8cfb838fa1bf3529c085c6dce1adf3d1eaf62) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-32960: For dataclasses, disallow inheriting frozen from non-frozen ↵Miss Islington (bot)2018-02-271-6/+13
| | | | | | | | classes and vice-versa, (GH-5919) (GH-5920) This restriction will be relaxed at a future date. (cherry picked from commit 2fa6b9eae07e2385e2acbf2e40093a21fb3a10c4) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-32929: Dataclasses: Change the tri-state hash parameter to the boolean ↵Miss Islington (bot)2018-02-261-79/+105
| | | | | | | | unsafe_hash. (GH-5891) (GH-5902) unsafe_hash=False is now the default. It is the same behavior as the old hash=None parameter. unsafe_hash=True will try to add __hash__. If it already exists, TypeError is raised. (cherry picked from commit dbf9cff48a4ad0fd58e1c623ce1f36c3dd3d5f38) Co-authored-by: Eric V. Smith <ericvsmith@users.noreply.github.com>
* bpo-32513: Make it easier to override dunders in dataclasses. (GH-5366)Eric V. Smith2018-01-281-82/+224
| | | Class authors no longer need to specify repr=False if they want to provide a custom __repr__ for dataclasses. The same thing applies for the other dunder methods that the dataclass decorator adds. If dataclass finds that a dunder methods is defined in the class, it will not overwrite it.
* bpo-32226: PEP 560: improve typing module (#4906)Ivan Levkivskyi2018-01-201-1/+2
| | | | This PR re-designs the internal typing API using the new PEP 560 features. However, there are only few minor changes in the public API.
* Fix obvious typos in docstrings (#5151)Raymond Hettinger2018-01-111-6/+7
|
* bpo-32506: Change dataclasses from OrderedDict to plain dict. (gh-5131)Eric V. Smith2018-01-071-8/+8
|
* Fix dataclasses docstring typo. (gh-5118)Eric V. Smith2018-01-071-2/+2
|
* bpo-32279: Add additional params to make_dataclass(), pass through to ↵Eric V. Smith2018-01-061-3/+7
| | | | dataclass(). (gh-5117)
* bpo-32278: Allow dataclasses.make_dataclass() to omit type information. ↵Eric V. Smith2018-01-061-6/+14
| | | | (gh-5115)
* bpo-32499: Add dataclasses.is_dataclass(obj), which returns True if obj is a ↵Eric V. Smith2018-01-061-6/+13
| | | | dataclass or an instance of one. (#5113)
* bpo-32427: Expose dataclasses.MISSING object. (#5045)Eric V. Smith2017-12-291-20/+21
|
* bpo-32214: Implement PEP 557: Data Classes (#4704)Eric V. Smith2017-12-041-0/+776