Skip to content

Commit fd9dce6

Browse files
author
Gray Memory Bot
committed
fix: asdict filter exclude list matches on name instead of attribute
1 parent 48ea7a1 commit fd9dce6

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hypothesis
2+
annotationlib

src/attr/_funcs.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def asdict(
6565
been applied.
6666
6767
Returns:
68-
Return type of *dict_factory*.
68+
An instance of *dict_factory*.
6969
7070
Raises:
7171
attrs.exceptions.NotAnAttrsClassError:
@@ -79,9 +79,9 @@ def asdict(
7979
"""
8080
attrs = fields(inst.__class__)
8181
rv = dict_factory()
82-
for a in attrs:
83-
v = getattr(inst, a.name)
84-
if filter is not None and not filter(a, v):
82+
for attr in attrs:
83+
v = getattr(inst, attr.name)
84+
if filter is not None and not filter(attr, v):
8585
continue
8686

8787
if value_serializer is not None:
@@ -90,9 +90,9 @@ def asdict(
9090
if recurse is True:
9191
value_type = type(v)
9292
if value_type in _ATOMIC_TYPES:
93-
rv[a.name] = v
93+
rv[attr.name] = v
9494
elif has(value_type):
95-
rv[a.name] = asdict(
95+
rv[attr.name] = asdict(
9696
v,
9797
recurse=True,
9898
filter=filter,
@@ -114,16 +114,16 @@ def asdict(
114114
for i in v
115115
]
116116
try:
117-
rv[a.name] = cf(items)
117+
rv[attr.name] = cf(items)
118118
except TypeError:
119119
if not issubclass(cf, tuple):
120120
raise
121121
# Workaround for TypeError: cf.__new__() missing 1 required
122122
# positional argument (which appears, for a namedturle)
123-
rv[a.name] = cf(*items)
123+
rv[attr.name] = cf(*items)
124124
elif issubclass(value_type, dict):
125125
df = dict_factory
126-
rv[a.name] = df(
126+
rv[attr.name] = df(
127127
(
128128
_asdict_anything(
129129
kk,
@@ -145,9 +145,9 @@ def asdict(
145145
for kk, vv in v.items()
146146
)
147147
else:
148-
rv[a.name] = v
148+
rv[attr.name] = v
149149
else:
150-
rv[a.name] = v
150+
rv[attr.name] = v
151151
return rv
152152

153153

0 commit comments

Comments
 (0)