-
Notifications
You must be signed in to change notification settings - Fork 25
Closed
Description
jsobj
returns a dictionary. If I wanted to write a decorator which returns the .items()
of whatever it is decorating (presumably a function which returns dictionaries), how would I do this, as my naive implementation didn't work. Can the functions in this module even be decorated in "the usual" manner?
My attempt:
from varname.helpers import jsobj
from functools import wraps
import unittest
def return_dict_items(func):
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs).items()
return wrapper
class TestWrapper(unittest.TestCase):
def test_wrapper(self):
foo = return_dict_items(jsobj)
a = 1
self.assertEqual([("a", 1)], list(foo(a)))
if __name__ == '__main__':
unittest.main()
However:
Expected :[('a', 1)]
Actual :[(<ast.Starred object at 0x10b96f850>, 1)]
Metadata
Metadata
Assignees
Labels
No labels