| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
| |
|
|
|
| |
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%.
|
| |
|
|
|
|
|
| |
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>
|
| |
|
| |
|
|
|
|
| |
This change renames the dataclass __replace__ method's first argument
name from 'obj' to 'self'.
|
|
|
|
|
|
| |
mixins (gh-109437)
Fix inheritance of frozen dataclass from non-frozen dataclass mixins
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
follows a default field. (gh-107842)
Add the name of the previous default argument field in an error message.
|
| |
|
|
|
|
|
| |
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>
|
|
|
| |
Co-authored-by: David Ellis <ducksual@gmail.com>
|
|
|
|
| |
dataclasses (#104041)
|
| |
|
|
|
|
| |
Co-authored-by: Carl Meyer <carl@oddbird.net>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
(#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
|
|
|
|
| |
(#102948)
|
|
|
|
| |
(#102075)
|
|
|
| |
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
|
|
|
| |
Update dataclasses.astuple and dataclasses.asdict docstrings to reflect that they deep copy objects in the field values.
|
| |
|
|
|
|
| |
subclasses of frozen dataclasses (gh-102573)
|
| |
|
|
|
| |
Avoid RecursionError on recursive dataclass field repr
|
|
|
|
| |
allows for a field named BUILTIN (gh-98143)
|
| |
|
| |
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
| |
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.
|
|
|
| |
Previously, when using `functools.wrap` around them (and inherit their docstrings), sphinx renders the docstrings badly and raises warnings about wrong indent.
|
| |
|
|
|
|
|
| |
list[int].__class__ returned type, and isinstance(list[int], type)
returned True. It caused numerous problems in code that checks
isinstance(x, type).
|
|
|
|
| |
(GH-93535)
|
|
|
|
| |
weakref-able. (#92160)
|
| |
|
|
|
|
|
| |
(GH-31980)
Do not include any members in __slots__ that are already in a base class's __slots__.
|
|
|
|
|
| |
__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.
|
|
|
|
| |
types.GenericAlias (GH-29294)
|
|
|
|
|
| |
(GH-29291)
For example, InitVar[list[int]].
|
|
|
|
|
| |
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.
|
| |
|
| |
|
|
|
| |
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
|
| |
|
|
|
|
|
| |
class (GH-25841)
bpo-44015: Raise a TypeError if KW_ONLY is specified more than once.
|
|
|
|
| |
the instance values. (GH-25786)
|