From 564fade9257c809d822a6ffe222f20d9b9ec0675 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Fri, 30 Jan 2015 09:50:33 +0100 Subject: [PATCH] Simplify attributes decorator --- attr/_make.py | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/attr/_make.py b/attr/_make.py index 44e66983..0c48d876 100644 --- a/attr/_make.py +++ b/attr/_make.py @@ -122,25 +122,23 @@ def attributes(maybe_cl=None, add_repr=True, add_cmp=True, add_hash=True, C(_private=42) :type add_init: bool """ + def wrap(cl): + _transform_attrs(cl) + if add_repr is True: + cl = _add_repr(cl) + if add_cmp is True: + cl = _add_cmp(cl) + if add_hash is True: + cl = _add_hash(cl) + if add_init is True: + cl = _add_init(cl) + return cl # attrs_or class type depends on the usage of the decorator. It's a class # if it's used as `@attributes` but ``None`` (or a value passed) if used # as `@attributes()`. if isinstance(maybe_cl, type): - _transform_attrs(maybe_cl) - return _add_init(_add_hash(_add_cmp(_add_repr(maybe_cl)))) + return wrap(maybe_cl) else: - def wrap(cl): - _transform_attrs(cl) - if add_repr is True: - cl = _add_repr(cl) - if add_cmp is True: - cl = _add_cmp(cl) - if add_hash is True: - cl = _add_hash(cl) - if add_init is True: - cl = _add_init(cl) - return cl - return wrap