Rename s to _add_methods
...and rename within __init__.py
This commit is contained in:
parent
14c5485cf5
commit
fdd41b0466
|
@ -8,8 +8,8 @@ from ._funcs import (
|
||||||
has,
|
has,
|
||||||
)
|
)
|
||||||
from ._make import (
|
from ._make import (
|
||||||
|
_add_methods as s,
|
||||||
_make_attr as ib,
|
_make_attr as ib,
|
||||||
s,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
__version__ = "0.0.0.dev0"
|
__version__ = "0.0.0.dev0"
|
||||||
|
|
|
@ -83,11 +83,11 @@ def _get_attrs(cl):
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
|
|
||||||
def s(maybe_cl=None, add_repr=True, add_cmp=True, add_hash=True,
|
def _add_methods(maybe_cl=None, add_repr=True, add_cmp=True, add_hash=True,
|
||||||
add_init=True):
|
add_init=True):
|
||||||
# attrs_or class type depends on the usage of the decorator.
|
# attrs_or class type depends on the usage of the decorator. It's a class
|
||||||
# It's a class if it's used as `@s` but ``None`` (or a value
|
# if it's used as `@_add_methods` but ``None`` (or a value passed) if used
|
||||||
# passed) if used as `@s()`.
|
# as `@_add_methods()`.
|
||||||
if isinstance(maybe_cl, type):
|
if isinstance(maybe_cl, type):
|
||||||
cl = maybe_cl
|
cl = maybe_cl
|
||||||
cl.__attrs_attrs__ = [
|
cl.__attrs_attrs__ = [
|
||||||
|
|
|
@ -8,11 +8,11 @@ from attr._funcs import ls, has, to_dict
|
||||||
from attr._make import (
|
from attr._make import (
|
||||||
Attribute,
|
Attribute,
|
||||||
_make_attr,
|
_make_attr,
|
||||||
s,
|
_add_methods,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@s
|
@_add_methods
|
||||||
class C(object):
|
class C(object):
|
||||||
x = _make_attr()
|
x = _make_attr()
|
||||||
y = _make_attr()
|
y = _make_attr()
|
||||||
|
@ -42,7 +42,6 @@ class TestLs(object):
|
||||||
"""
|
"""
|
||||||
Returns a list of `Attribute`.
|
Returns a list of `Attribute`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert all(isinstance(a, Attribute) for a in ls(C))
|
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.
|
Returns `True` on decorated classes even if there are no attributes.
|
||||||
"""
|
"""
|
||||||
@s
|
@_add_methods
|
||||||
class D(object):
|
class D(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@ import pytest
|
||||||
from attr._make import (
|
from attr._make import (
|
||||||
Attribute,
|
Attribute,
|
||||||
_CountingAttr,
|
_CountingAttr,
|
||||||
|
_add_methods,
|
||||||
_get_attrs,
|
_get_attrs,
|
||||||
_make_attr,
|
_make_attr,
|
||||||
s,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class TestGetAttrs(object):
|
||||||
"""
|
"""
|
||||||
Returns attributes in correct order.
|
Returns attributes in correct order.
|
||||||
"""
|
"""
|
||||||
@s
|
@_add_methods
|
||||||
class C(object):
|
class C(object):
|
||||||
z = _make_attr()
|
z = _make_attr()
|
||||||
y = _make_attr()
|
y = _make_attr()
|
||||||
|
@ -58,22 +58,22 @@ class TestGetAttrs(object):
|
||||||
"""
|
"""
|
||||||
No attributes returns an empty list.
|
No attributes returns an empty list.
|
||||||
"""
|
"""
|
||||||
@s
|
@_add_methods
|
||||||
class C(object):
|
class C(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
assert [] == _get_attrs(C)
|
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):
|
def test_sets_attrs(self):
|
||||||
"""
|
"""
|
||||||
Sets the `__attrs_attrs__` class attribute with a list of `Attribute`s.
|
Sets the `__attrs_attrs__` class attribute with a list of `Attribute`s.
|
||||||
"""
|
"""
|
||||||
@s
|
@_add_methods
|
||||||
class C(object):
|
class C(object):
|
||||||
x = _make_attr()
|
x = _make_attr()
|
||||||
assert "x" == C.__attrs_attrs__[0].name
|
assert "x" == C.__attrs_attrs__[0].name
|
||||||
|
@ -83,7 +83,7 @@ class TestS(object):
|
||||||
"""
|
"""
|
||||||
No attributes, no problems.
|
No attributes, no problems.
|
||||||
"""
|
"""
|
||||||
@s
|
@_add_methods
|
||||||
class C3(object):
|
class C3(object):
|
||||||
pass
|
pass
|
||||||
assert "C3()" == repr(C3())
|
assert "C3()" == repr(C3())
|
||||||
|
|
Loading…
Reference in New Issue