Skip to content

Commit b167887

Browse files
committed
Add docs and changelog for new feature
1 parent c57c51d commit b167887

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

changelog.d/1068.change.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
filters ``exclude`` and ``include`` now support to pass literal name of attribtes in ``str`` format

docs/examples.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ For that, {func}`attrs.asdict` offers a callback that decides whether an attribu
215215
{'users': [{'email': 'jane@doe.invalid'}, {'email': 'joe@doe.invalid'}]}
216216
```
217217

218-
For the common case where you want to [`include`](attrs.filters.include) or [`exclude`](attrs.filters.exclude) certain types or attributes, *attrs* ships with a few helpers:
218+
For the common case where you want to [`include`](attrs.filters.include) or [`exclude`](attrs.filters.exclude) certain types, string name or attributes, *attrs* ships with a few helpers:
219219

220220
```{doctest}
221221
>>> from attrs import asdict, filters, fields
@@ -228,7 +228,7 @@ For the common case where you want to [`include`](attrs.filters.include) or [`ex
228228
229229
>>> asdict(
230230
... User("jane", "s33kred", 42),
231-
... filter=filters.exclude(fields(User).password, int))
231+
... filter=filters.exclude(fields(User).password, int, "password"))
232232
{'login': 'jane'}
233233
234234
>>> @define
@@ -238,7 +238,7 @@ For the common case where you want to [`include`](attrs.filters.include) or [`ex
238238
... z: int
239239
240240
>>> asdict(C("foo", "2", 3),
241-
... filter=filters.include(int, fields(C).x))
241+
... filter=filters.include(int, fields(C).x, "x"))
242242
{'x': 'foo', 'z': 3}
243243
```
244244

src/attr/filters.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def include(*what):
2727
`attrs.Attribute`\\ s
2828
2929
:rtype: `callable`
30+
31+
.. versionchanged:: 22.2.0 Accept field name string as input argument
3032
"""
3133
cls, names, attrs = _split_what(what)
3234

@@ -49,6 +51,8 @@ def exclude(*what):
4951
`attrs.Attribute`\\ s.
5052
5153
:rtype: `callable`
54+
55+
.. versionchanged:: 22.2.0 Accept field name string as input argument
5256
"""
5357
cls, names, attrs = _split_what(what)
5458

tests/typing_example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ def accessing_from_attr() -> None:
432432
attr.converters.optional
433433
attr.exceptions.FrozenError
434434
attr.filters.include
435+
attr.filters.exclude
435436
attr.setters.frozen
436437
attr.validators.and_
437438
attr.cmp_using
@@ -444,6 +445,7 @@ def accessing_from_attrs() -> None:
444445
attrs.converters.optional
445446
attrs.exceptions.FrozenError
446447
attrs.filters.include
448+
attr.filters.exclude
447449
attrs.setters.frozen
448450
attrs.validators.and_
449451
attrs.cmp_using

0 commit comments

Comments
 (0)