forwardable
Advanced tools
| from unittest import TestCase | ||
| from forwardable import def_delegators | ||
| class TestDefDelegators(TestCase): | ||
| def test_def_delegators(self): | ||
| class Foo(object): | ||
| def_delegators("dct", ["keys", "values"]) | ||
| dct = {'key': 42} | ||
| foo = Foo() | ||
| self.assertEqual(list(foo.keys()), ['key']) | ||
| self.assertEqual(list(foo.values()), [42]) | ||
| def test_attr_splitting(self): | ||
| class Foo(object): | ||
| def_delegators("dct", "keys, values") | ||
| dct = {'key': 42} | ||
| foo = Foo() | ||
| self.assertEqual(list(foo.keys()), ['key']) | ||
| self.assertEqual(list(foo.values()), [42]) |
+5
-0
@@ -0,1 +1,6 @@ | ||
| * 0.4.0 | ||
| - ``def_delegators`` now accepts string form for 2nd argument. | ||
| Just like ``collections.namedtuple`` does. | ||
| * 0.3.1 | ||
@@ -2,0 +7,0 @@ |
| Metadata-Version: 1.1 | ||
| Name: forwardable | ||
| Version: 0.3.1 | ||
| Version: 0.4.0 | ||
| Summary: Forwardable as in Ruby's stdlib | ||
@@ -43,3 +43,3 @@ Home-page: https://github.com/5long/forwardable | ||
| class Foo(object): | ||
| def_delegators('bar', ('add', '__len__')) | ||
| def_delegators('bar', 'add, __len__') | ||
@@ -46,0 +46,0 @@ def __init__(self): |
@@ -13,2 +13,3 @@ CHANGELOG.rst | ||
| forwardable/test/test_def_delegator.py | ||
| forwardable/test/test_def_delegators.py | ||
| forwardable/test/test_forwardable.py |
@@ -8,3 +8,3 @@ """ | ||
| class Foo(object): | ||
| def_delegators('bar', ('add', '__len__')) | ||
| def_delegators('bar', 'add, __len__') | ||
@@ -19,3 +19,3 @@ def __init__(self) | ||
| __version__ = '0.3.1' | ||
| __version__ = '0.4.0' | ||
@@ -64,4 +64,13 @@ __all__ = ["forwardable", "def_delegator", "def_delegators"] | ||
| The ``attrs`` argument can be an iterable of attribute names, or | ||
| a comma-and-spaces separated string of attribute names. The following | ||
| form works identically: | ||
| def_delegators(wrapped, ('foo', 'bar')) # Tuple of attribute names | ||
| def_delegators(wrapped, 'foo bar') # Separated by space | ||
| def_delegators(wrapped, 'foo, bar') # With optional comma | ||
| Must be called in a class scope. | ||
| """ | ||
| attrs = split_attrs(attrs) if isinstance(attrs, basestring) else attrs | ||
| for a in attrs: | ||
@@ -78,2 +87,5 @@ def_delegator(wrapped, a, _call_stack_depth=2) | ||
| def split_attrs(attrs): | ||
| return attrs.replace(',', ' ').split() | ||
| def inject(frame): | ||
@@ -80,0 +92,0 @@ if not is_module_frame(frame): |
@@ -22,12 +22,2 @@ from unittest import TestCase | ||
| def test_def_delegators(self): | ||
| class Foo(object): | ||
| def_delegators("dct", ["keys", "values"]) | ||
| dct = {'key': 42} | ||
| foo = Foo() | ||
| self.assertEqual(list(foo.keys()), ['key']) | ||
| self.assertEqual(list(foo.values()), [42]) | ||
| def test_called_in_non_class_scope(self): | ||
@@ -34,0 +24,0 @@ with self.assertRaises(NotCalledInClassScope): |
+2
-2
| Metadata-Version: 1.1 | ||
| Name: forwardable | ||
| Version: 0.3.1 | ||
| Version: 0.4.0 | ||
| Summary: Forwardable as in Ruby's stdlib | ||
@@ -43,3 +43,3 @@ Home-page: https://github.com/5long/forwardable | ||
| class Foo(object): | ||
| def_delegators('bar', ('add', '__len__')) | ||
| def_delegators('bar', 'add, __len__') | ||
@@ -46,0 +46,0 @@ def __init__(self): |
+1
-1
@@ -35,3 +35,3 @@ Forwardable | ||
| class Foo(object): | ||
| def_delegators('bar', ('add', '__len__')) | ||
| def_delegators('bar', 'add, __len__') | ||
@@ -38,0 +38,0 @@ def __init__(self): |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
19951
5.48%16
6.67%210
9.95%