You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Class-level `kw_only=True` behavior is now consistent with `dataclasses`.
20
+
21
+
Previously, a class that sets `kw_only=True` makes all attributes keyword-only, including those from base classes.
22
+
If an attribute sets `kw_only=False`, that setting is ignored, and it is still made keyword-only.
23
+
24
+
Now, only the attributes defined in that class that doesn't explicitly set `kw_only=False` are made keyword-only.
25
+
26
+
This shouldn't be a problem for most users, unless you have a pattern like this:
27
+
28
+
```python
29
+
@attrs.define(kw_only=True)
30
+
classBase:
31
+
a: int
32
+
b: int= attrs.field(default=1, kw_only=False)
33
+
34
+
@attrs.define
35
+
classSubclass(Base):
36
+
c: int
37
+
```
38
+
39
+
Here, we have a `kw_only=True`*attrs* class (`Base`) with an attribute that sets `kw_only=False` and has a default (`Base.b`), and then create a subclass (`Subclass`) with required arguments (`Subclass.c`).
40
+
Previously this would work, since it would make `Base.b` keyword-only, but now this fails since `Base.b` is positional, and we have a required positional argument (`Subclass.c`) following another argument with defaults.
- Values passed to the `__init__()` method of `attrs` classes are now correctly passed to `__attrs_pre_init__()` instead of their default values (in cases where *kw_only* was not specified).
-`attrs.validators.deep_iterator()` and `attrs.validators.deep_mapping()` now accept lists and tuples for all validators and wrap them into a `attrs.validators.and_()`.
0 commit comments