Skip to content

Commit 689a0e6

Browse files
authored
Simplify & optimize own attribute detection (#1322)
1 parent f7e4e91 commit 689a0e6

1 file changed

Lines changed: 2 additions & 14 deletions

File tree

src/attr/_make.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -304,26 +304,14 @@ def _has_own_attribute(cls, attrib_name):
304304
"""
305305
Check whether *cls* defines *attrib_name* (and doesn't just inherit it).
306306
"""
307-
attr = getattr(cls, attrib_name, _SENTINEL)
308-
if attr is _SENTINEL:
309-
return False
310-
311-
for base_cls in cls.__mro__[1:]:
312-
a = getattr(base_cls, attrib_name, None)
313-
if attr is a:
314-
return False
315-
316-
return True
307+
return attrib_name in cls.__dict__
317308

318309

319310
def _get_annotations(cls):
320311
"""
321312
Get annotations for *cls*.
322313
"""
323-
if _has_own_attribute(cls, "__annotations__"):
324-
return cls.__annotations__
325-
326-
return {}
314+
return cls.__dict__.get("__annotations__", {})
327315

328316

329317
def _collect_base_attrs(cls, taken_attr_names):

0 commit comments

Comments
 (0)