Rename s to _add_methods

...and rename within __init__.py
This commit is contained in:
Hynek Schlawack 2015-01-28 11:35:16 +01:00
parent 14c5485cf5
commit fdd41b0466
4 changed files with 16 additions and 17 deletions

View File

@ -8,8 +8,8 @@ from ._funcs import (
has,
)
from ._make import (
_add_methods as s,
_make_attr as ib,
s,
)
__version__ = "0.0.0.dev0"

View File

@ -83,11 +83,11 @@ def _get_attrs(cl):
return attrs
def s(maybe_cl=None, add_repr=True, add_cmp=True, add_hash=True,
add_init=True):
# attrs_or class type depends on the usage of the decorator.
# It's a class if it's used as `@s` but ``None`` (or a value
# passed) if used as `@s()`.
def _add_methods(maybe_cl=None, add_repr=True, add_cmp=True, add_hash=True,
add_init=True):
# attrs_or class type depends on the usage of the decorator. It's a class
# if it's used as `@_add_methods` but ``None`` (or a value passed) if used
# as `@_add_methods()`.
if isinstance(maybe_cl, type):
cl = maybe_cl
cl.__attrs_attrs__ = [

View File

@ -8,11 +8,11 @@ from attr._funcs import ls, has, to_dict
from attr._make import (
Attribute,
_make_attr,
s,
_add_methods,
)
@s
@_add_methods
class C(object):
x = _make_attr()
y = _make_attr()
@ -42,7 +42,6 @@ class TestLs(object):
"""
Returns a list of `Attribute`.
"""
assert all(isinstance(a, Attribute) for a in ls(C))
@ -86,7 +85,7 @@ class TestHas(object):
"""
Returns `True` on decorated classes even if there are no attributes.
"""
@s
@_add_methods
class D(object):
pass

View File

@ -7,9 +7,9 @@ import pytest
from attr._make import (
Attribute,
_CountingAttr,
_add_methods,
_get_attrs,
_make_attr,
s,
)
@ -46,7 +46,7 @@ class TestGetAttrs(object):
"""
Returns attributes in correct order.
"""
@s
@_add_methods
class C(object):
z = _make_attr()
y = _make_attr()
@ -58,22 +58,22 @@ class TestGetAttrs(object):
"""
No attributes returns an empty list.
"""
@s
@_add_methods
class C(object):
pass
assert [] == _get_attrs(C)
class TestS(object):
class TestAddMethods(object):
"""
Tests for the `s` class decorator.
Tests for the `_add_methods` class decorator.
"""
def test_sets_attrs(self):
"""
Sets the `__attrs_attrs__` class attribute with a list of `Attribute`s.
"""
@s
@_add_methods
class C(object):
x = _make_attr()
assert "x" == C.__attrs_attrs__[0].name
@ -83,7 +83,7 @@ class TestS(object):
"""
No attributes, no problems.
"""
@s
@_add_methods
class C3(object):
pass
assert "C3()" == repr(C3())