本文整理汇总了Python中pypy.interpreter.argument.Arguments._match_signature方法的典型用法代码示例。如果您正苦于以下问题:Python Arguments._match_signature方法的具体用法?Python Arguments._match_signature怎么用?Python Arguments._match_signature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pypy.interpreter.argument.Arguments
的用法示例。
在下文中一共展示了Arguments._match_signature方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_argument_unicode
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import _match_signature [as 别名]
def test_argument_unicode(self):
space = DummySpace()
w_starstar = space.wrap({u"abc": 5})
args = Arguments(space, [], w_starstararg=w_starstar)
l = [None]
args._match_signature(None, l, Signature(["abc"]))
assert len(l) == 1
assert l[0] == space.wrap(5)
示例2: test_args_parsing
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import _match_signature [as 别名]
def test_args_parsing(self):
space = DummySpace()
args = Arguments(space, [])
calls = []
def _match_signature(w_firstarg, scope_w, signature,
defaults_w=None, w_kw_defs=None, blindargs=0):
defaults_w = [] if defaults_w is None else defaults_w
calls.append((w_firstarg, scope_w, signature.argnames, signature.has_vararg(),
signature.has_kwarg(), defaults_w, w_kw_defs, blindargs))
args._match_signature = _match_signature
scope_w = args.parse_obj(None, "foo", Signature(["a", "b"], None, None))
assert len(calls) == 1
assert calls[0] == (None, [None, None], ["a", "b"], False, False,
[], None, 0)
assert calls[0][1] is scope_w
calls = []
scope_w = args.parse_obj(None, "foo", Signature(["a", "b"], "args", None),
blindargs=1)
assert len(calls) == 1
assert calls[0] == (None, [None, None, None], ["a", "b"], True, False,
[], None, 1)
calls = []
scope_w = args.parse_obj(None, "foo", Signature(["a", "b"], "args", "kw"),
defaults_w=['x', 'y'])
assert len(calls) == 1
assert calls[0] == (None, [None, None, None, None], ["a", "b"],
True, True,
["x", "y"], None, 0)
calls = []
scope_w = args.parse_obj("obj", "foo", Signature(["a", "b"], "args", "kw"),
defaults_w=['x', 'y'], blindargs=1)
assert len(calls) == 1
assert calls[0] == ("obj", [None, None, None, None], ["a", "b"],
True, True,
["x", "y"], None, 1)
class FakeArgErr(ArgErr):
def getmsg(self):
return "msg"
def _match_signature(*args):
raise FakeArgErr()
args._match_signature = _match_signature
excinfo = py.test.raises(OperationError, args.parse_obj, "obj", "foo",
Signature(["a", "b"], None, None))
assert excinfo.value.w_type is TypeError
assert excinfo.value.get_w_value(space) == "foo() msg"
示例3: test_args_parsing_into_scope
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import _match_signature [as 别名]
def test_args_parsing_into_scope(self):
space = DummySpace()
args = Arguments(space, [])
calls = []
def _match_signature(w_firstarg, scope_w, signature,
defaults_w=[], blindargs=0):
calls.append((w_firstarg, scope_w, signature.argnames, signature.has_vararg(),
signature.has_kwarg(), defaults_w, blindargs))
args._match_signature = _match_signature
scope_w = [None, None]
args.parse_into_scope(None, scope_w, "foo", Signature(["a", "b"], None, None))
assert len(calls) == 1
assert calls[0] == (None, scope_w, ["a", "b"], False, False,
[], 0)
assert calls[0][1] is scope_w
calls = []
scope_w = [None, None, None, None]
args.parse_into_scope(None, scope_w, "foo", Signature(["a", "b"], "args", "kw"),
defaults_w=['x', 'y'])
assert len(calls) == 1
assert calls[0] == (None, scope_w, ["a", "b"],
True, True,
["x", "y"], 0)
calls = []
scope_w = [None, None, None, None]
args.parse_into_scope("obj", scope_w, "foo", Signature(["a", "b"],
"args", "kw"),
defaults_w=['x', 'y'])
assert len(calls) == 1
assert calls[0] == ("obj", scope_w, ["a", "b"],
True, True,
["x", "y"], 0)
class FakeArgErr(ArgErr):
def getmsg(self, fname):
return "msg "+fname
def _match_signature(*args):
raise FakeArgErr()
args._match_signature = _match_signature
excinfo = py.test.raises(OperationError, args.parse_into_scope,
"obj", [None, None], "foo",
Signature(["a", "b"], None, None))
assert excinfo.value.w_type is TypeError
assert excinfo.value._w_value == "msg foo"
示例4: test_match_kwds2
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import _match_signature [as 别名]
def test_match_kwds2(self):
space = DummySpace()
kwds = [("c", 3), ('d', 4)]
for i in range(4):
kwds_w = dict(kwds[:i])
keywords = kwds_w.keys()
keywords_w = kwds_w.values()
w_kwds = dict(kwds[i:])
if i == 3:
w_kwds = None
args = Arguments(space, [1, 2], keywords, keywords_w, w_starstararg=w_kwds)
l = [None, None, None, None]
args._match_signature(None, l, Signature(["a", "b", "c"], None, "**"))
assert l == [1, 2, 3, {'d': 4}]
示例5: test_match_kwds
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import _match_signature [as 别名]
def test_match_kwds(self):
space = DummySpace()
for i in range(3):
kwds = [("c", 3)]
kwds_w = dict(kwds[:i])
keywords = kwds_w.keys()
keywords_w = kwds_w.values()
w_kwds = dict(kwds[i:])
if i == 2:
w_kwds = None
assert len(keywords) == len(keywords_w)
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None]
args._match_signature(None, l, Signature(["a", "b", "c"]), defaults_w=[4])
assert l == [1, 2, 3]
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None, None]
args._match_signature(None, l, Signature(["a", "b", "b1", "c"]), defaults_w=[4, 5])
assert l == [1, 2, 4, 3]
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None, None]
args._match_signature(None, l, Signature(["a", "b", "c", "d"]), defaults_w=[4, 5])
assert l == [1, 2, 3, 5]
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None, None]
py.test.raises(ArgErr, args._match_signature, None, l,
Signature(["c", "b", "a", "d"]), defaults_w=[4, 5])
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None, None]
py.test.raises(ArgErr, args._match_signature, None, l,
Signature(["a", "b", "c1", "d"]), defaults_w=[4, 5])
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None]
args._match_signature(None, l, Signature(["a", "b"], None, "**"))
assert l == [1, 2, {'c': 3}]
示例6: test_blindargs
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import _match_signature [as 别名]
def test_blindargs(self):
space = DummySpace()
kwds = [("a", 3), ("b", 4)]
for i in range(4):
kwds_w = dict(kwds[:i])
keywords = kwds_w.keys()
keywords_w = kwds_w.values()
w_kwds = dict(kwds[i:])
if i == 3:
w_kwds = None
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None]
args._match_signature(None, l, Signature(["a", "b"], None, "**"), blindargs=2)
assert l == [1, 2, {"a": 3, "b": 4}]
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None]
py.test.raises(ArgErrUnknownKwds, args._match_signature, None, l, Signature(["a", "b"]), blindargs=2)
示例7: test_starstarargs_special
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import _match_signature [as 别名]
def test_starstarargs_special(self):
class kwargs(object):
def __init__(self, k, v):
self.k = k
self.v = v
class MyDummySpace(DummySpace):
def view_as_kwargs(self, kw):
if isinstance(kw, kwargs):
return kw.k, kw.v
return None, None
space = MyDummySpace()
for i in range(3):
kwds = [("c", 3)]
kwds_w = dict(kwds[:i])
keywords = kwds_w.keys()
keywords_w = kwds_w.values()
rest = dict(kwds[i:])
w_kwds = kwargs(rest.keys(), rest.values())
if i == 2:
w_kwds = None
assert len(keywords) == len(keywords_w)
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None]
args._match_signature(None, l, Signature(["a", "b", "c"]), defaults_w=[4])
assert l == [1, 2, 3]
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None, None]
args._match_signature(None, l, Signature(["a", "b", "b1", "c"]), defaults_w=[4, 5])
assert l == [1, 2, 4, 3]
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None, None]
args._match_signature(None, l, Signature(["a", "b", "c", "d"]), defaults_w=[4, 5])
assert l == [1, 2, 3, 5]
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None, None]
py.test.raises(ArgErr, args._match_signature, None, l,
Signature(["c", "b", "a", "d"]), defaults_w=[4, 5])
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None, None]
py.test.raises(ArgErr, args._match_signature, None, l,
Signature(["a", "b", "c1", "d"]), defaults_w=[4, 5])
args = Arguments(space, [1, 2], keywords[:], keywords_w[:], w_starstararg=w_kwds)
l = [None, None, None]
args._match_signature(None, l, Signature(["a", "b"], None, "**"))
assert l == [1, 2, {'c': 3}]
excinfo = py.test.raises(OperationError, Arguments, space, [], ["a"],
[1], w_starstararg=kwargs(["a"], [2]))
assert excinfo.value.w_type is TypeError
示例8: test_match4
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import _match_signature [as 别名]
def test_match4(self):
space = DummySpace()
values = [4, 5, 6, 7]
for havefirstarg in [0, 1]:
for i in range(len(values)-havefirstarg):
arglist = values[havefirstarg:i+havefirstarg]
starargs = tuple(values[i+havefirstarg:])
if havefirstarg:
firstarg = values[0]
else:
firstarg = None
args = Arguments(space, arglist, w_stararg=starargs)
l = [None, None, None, None]
args._match_signature(firstarg, l, Signature(["a", "b", "c", "d"]))
assert l == [4, 5, 6, 7]
args = Arguments(space, arglist, w_stararg=starargs)
l = [None, None, None, None, None, None]
py.test.raises(ArgErr, args._match_signature, firstarg, l, Signature(["a"]))
args = Arguments(space, arglist, w_stararg=starargs)
l = [None, None, None, None, None, None]
py.test.raises(ArgErr, args._match_signature, firstarg, l, Signature(["a", "b", "c", "d", "e"]))
args = Arguments(space, arglist, w_stararg=starargs)
l = [None, None, None, None, None, None]
py.test.raises(ArgErr, args._match_signature, firstarg, l, Signature(["a", "b", "c", "d", "e"], "*"))
l = [None, None, None, None, None]
args = Arguments(space, arglist, w_stararg=starargs)
args._match_signature(firstarg, l, Signature(["a", "b", "c", "d", "e"]), defaults_w=[1])
assert l == [4, 5, 6, 7, 1]
for j in range(len(values)):
l = [None] * (j + 1)
args = Arguments(space, arglist, w_stararg=starargs)
args._match_signature(firstarg, l, Signature(["a", "b", "c", "d", "e"][:j], "*"))
assert l == values[:j] + [tuple(values[j:])]
l = [None, None, None, None, None]
args = Arguments(space, arglist, w_stararg=starargs)
args._match_signature(firstarg, l, Signature(["a", "b", "c", "d"], None, "**"))
assert l == [4, 5, 6, 7, {}]
示例9: test_match0
# 需要导入模块: from pypy.interpreter.argument import Arguments [as 别名]
# 或者: from pypy.interpreter.argument.Arguments import _match_signature [as 别名]
def test_match0(self):
space = DummySpace()
args = Arguments(space, [])
l = []
args._match_signature(None, l, Signature([]))
assert len(l) == 0
l = [None, None]
args = Arguments(space, [])
py.test.raises(ArgErr, args._match_signature, None, l, Signature(["a"]))
args = Arguments(space, [])
py.test.raises(ArgErr, args._match_signature, None, l, Signature(["a"], "*"))
args = Arguments(space, [])
l = [None]
args._match_signature(None, l, Signature(["a"]), defaults_w=[1])
assert l == [1]
args = Arguments(space, [])
l = [None]
args._match_signature(None, l, Signature([], "*"))
assert l == [()]
args = Arguments(space, [])
l = [None]
args._match_signature(None, l, Signature([], None, "**"))
assert l == [{}]
args = Arguments(space, [])
l = [None, None]
py.test.raises(ArgErr, args._match_signature, 41, l, Signature([]))
args = Arguments(space, [])
l = [None]
args._match_signature(1, l, Signature(["a"]))
assert l == [1]
args = Arguments(space, [])
l = [None]
args._match_signature(1, l, Signature([], "*"))
assert l == [(1,)]