示例#1
0
 def test_attr_conservation_after(self):
     func = f('s, a')
     pt = modifiers.kwoargs('a')(func)
     pt.attr = object()
     self.assertIs(pt.attr, modifiers.kwoargs('a')(pt).attr)
     bpt = pt.__get__(object(), object)
     self.assertIs(pt.attr, bpt.attr)
     self.assertIs(pt.attr, modifiers.kwoargs('a')(bpt).attr)
示例#2
0
 def test_attr_conservation_after(self):
     func = f('s, a')
     pt = modifiers.kwoargs('a')(func)
     pt.attr = object()
     self.assertIs(pt.attr, modifiers.kwoargs('a')(pt).attr)
     bpt = pt.__get__(object(), object)
     self.assertIs(pt.attr, bpt.attr)
     self.assertIs(pt.attr, modifiers.kwoargs('a')(bpt).attr)
示例#3
0
 def test_specifiers_sig_after(self):
     inner = f('a, b', name='inner')
     outer = f('x, y, z, *args, **kwargs', name='outer')
     pt = modifiers.kwoargs('z')(outer)
     pt = specifiers.forwards_to_function(inner)(pt)
     sig = specifiers.signature(pt)
     self.assertSigsEqual(sig, s('x, y, a, b, *, z'))
     self.assertSourcesEqual(
         sig.sources, {'inner': 'ab', 'outer': 'xyz',
                       '+depths': ['outer', 'inner']})
     self.assertEqual(sig.sources['x'], [pt])
示例#4
0
 def test_specifiers_sig_after(self):
     inner = f('a, b', name='inner')
     outer = f('x, y, z, *args, **kwargs', name='outer')
     pt = modifiers.kwoargs('z')(outer)
     pt = specifiers.forwards_to_function(inner)(pt)
     sig = specifiers.signature(pt)
     self.assertSigsEqual(sig, s('x, y, a, b, *, z'))
     self.assertSourcesEqual(sig.sources, {
         'inner': 'ab',
         'outer': 'xyz',
         '+depths': ['outer', 'inner']
     })
     self.assertEqual(sig.sources['x'], [pt])
示例#5
0
 def _test(self, expected_sig_str, orig_sig_str, start):
     orig_func = f(orig_sig_str)
     func = modifiers.kwoargs(start=start)(orig_func)
     self.assertSigsEqual(s(expected_sig_str), signature(func))
示例#6
0
 def test_kwoargs_start_missing_raises(self):
     func = f('')
     self.assertRaises(ValueError, modifiers.kwoargs(start='a'), func)
示例#7
0
 def test_merge_other(self):
     orig_func = f('a, b')
     func = modifiers.kwoargs('b')(modifiers.posoargs(end='a')(orig_func))
     self.assertSigsEqual(s('<a>, *, b'), signature(func))
示例#8
0
 def test_kwoargs_noop(self):
     func = f('')
     self.assertTrue(func is modifiers.kwoargs()(func))
示例#9
0
 def _test(self, expected_sig_str, orig_sig_str, start):
     orig_func = f(orig_sig_str)
     func = modifiers.kwoargs(start=start)(orig_func)
     self.assertSigsEqual(s(expected_sig_str), signature(func))
示例#10
0
 def test_kwoargs_start_missing_raises(self):
     func = f('')
     self.assertRaises(ValueError, modifiers.kwoargs(start='a'), func)
示例#11
0
 def test_merge_other(self):
     orig_func = f('a, b')
     func = modifiers.kwoargs('b')(modifiers.posoargs(end='a')(orig_func))
     self.assertSigsEqual(s('<a>, *, b'), signature(func))
示例#12
0
 def test_kwoargs_noop(self):
     func = f('')
     self.assertTrue(func is modifiers.kwoargs()(func))
示例#13
0
"""

from functools import partial, update_wrapper

from sigtools import _util, modifiers, signatures, _signatures

__all__ = [
    'signature',
    'forwards_to_function', 'forwards_to_method',
    'forwards_to_super', 'apply_forwards_to_super',
    'forwards',
    'forger_function', 'set_signature_forger', 'as_forged'
    ]


_kwowr = modifiers.kwoargs('obj')


signature = _signatures.forged_signature


class _AsForged(object):
    def __init__(self):
        self.currently_computing = set()

    def __get__(self, instance, owner):
        obj = owner if instance is None else instance
        if obj in self.currently_computing:
            raise AttributeError
        try:
            self.currently_computing.add(obj)
示例#14
0
"""

from functools import partial, update_wrapper

from sigtools import _util, modifiers, signatures, _specifiers

__all__ = [
    'signature',
    'forwards_to_function', 'forwards_to_method',
    'forwards_to_super', 'apply_forwards_to_super',
    'forwards',
    'forger_function', 'set_signature_forger', 'as_forged'
    ]


_kwowr = modifiers.kwoargs('obj')


signature = _specifiers.forged_signature


class _AsForged(object):
    def __init__(self):
        self.currently_computing = set()

    def __get__(self, instance, owner):
        obj = owner if instance is None else instance
        if obj in self.currently_computing:
            raise AttributeError
        try:
            self.currently_computing.add(obj)