本文整理汇总了Python中pypy.interpreter.argument.Arguments类的典型用法代码示例。如果您正苦于以下问题:Python Arguments类的具体用法?Python Arguments怎么用?Python Arguments使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Arguments类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: appcaller
def appcaller(space, *args_w):
if not isinstance(space, ObjSpace):
raise TypeError("first argument must be a space instance.")
# redirect if the space handles this specially
# XXX can this be factored a bit less flow space dependently?
if hasattr(space, 'specialcases'):
sc = space.specialcases
if ApplevelClass in sc:
ret_w = sc[ApplevelClass](space, self, name, args_w)
if ret_w is not None: # it was RPython
return ret_w
# the last argument can be an Arguments
if not args_w:
args = Arguments(space, [])
else:
args = args_w[-1]
assert args is not None
if not isinstance(args, AbstractArguments):
args = Arguments(space, list(args_w))
else:
# ...which is merged with the previous arguments, if any
if len(args_w) > 1:
more_args_w, more_kwds_w = args.unpack()
args = Arguments(space,
list(args_w[:-1]) + more_args_w,
more_kwds_w)
w_func = self.wget(space, name)
return space.call_args(w_func, args)
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:28,代码来源:gateway.py
示例2: callparse
def callparse(rtyper, graph, hop, opname, r_self=None):
"""Parse the arguments of 'hop' when calling the given 'graph'.
"""
rinputs = getrinputs(rtyper, graph)
space = RPythonCallsSpace()
def args_h(start):
return [VarHolder(i, hop.args_s[i]) for i in range(start, hop.nb_args)]
if r_self is None:
start = 1
else:
start = 0
rinputs[0] = r_self
if opname == "simple_call":
arguments = Arguments(space, args_h(start))
elif opname == "call_args":
arguments = Arguments.fromshape(space, hop.args_s[start].const, args_h(start + 1)) # shape
# parse the arguments according to the function we are calling
signature = graph.signature
defs_h = []
if graph.defaults:
for x in graph.defaults:
defs_h.append(ConstHolder(x))
try:
holders = arguments.match_signature(signature, defs_h)
except ArgErr, e:
raise TyperError, "signature mismatch: %s" % e.getmsg(graph.name)
开发者ID:,项目名称:,代码行数:28,代码来源:
示例3: test_prepend
def test_prepend(self):
space = DummySpace()
args = Arguments(space, ["0"])
args1 = args.prepend("thingy")
assert args1 is not args
assert args1.arguments_w == ["thingy", "0"]
assert args1.keywords is args.keywords
assert args1.keywords_w is args.keywords_w
开发者ID:alkorzt,项目名称:pypy,代码行数:8,代码来源:test_argument.py
示例4: test_argument_unicode
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)
开发者ID:,项目名称:,代码行数:8,代码来源:
示例5: test_topacked_frompacked
def test_topacked_frompacked(self):
space = DummySpace()
args = Arguments(space, [1], ['a', 'b'], [2, 3])
w_args, w_kwds = args.topacked()
assert w_args == (1,)
assert w_kwds == {'a': 2, 'b': 3}
args1 = Arguments.frompacked(space, w_args, w_kwds)
assert args.arguments_w == [1]
assert set(args.keywords) == set(['a', 'b'])
assert args.keywords_w[args.keywords.index('a')] == 2
assert args.keywords_w[args.keywords.index('b')] == 3
开发者ID:alkorzt,项目名称:pypy,代码行数:11,代码来源:test_argument.py
示例6: test_fixedunpacked
def test_fixedunpacked(self):
space = DummySpace()
args = Arguments(space, [], ["k"], [1])
py.test.raises(ValueError, args.fixedunpack, 1)
args = Arguments(space, ["a", "b"])
py.test.raises(ValueError, args.fixedunpack, 0)
py.test.raises(ValueError, args.fixedunpack, 1)
py.test.raises(ValueError, args.fixedunpack, 3)
py.test.raises(ValueError, args.fixedunpack, 4)
assert args.fixedunpack(2) == ['a', 'b']
开发者ID:alkorzt,项目名称:pypy,代码行数:13,代码来源:test_argument.py
示例7: test_match_kwds2
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}]
开发者ID:alkorzt,项目名称:pypy,代码行数:14,代码来源:test_argument.py
示例8: test_args_parsing_into_scope
def test_args_parsing_into_scope(self):
space = DummySpace()
args = Arguments(space, [])
calls = []
def _match_signature(w_firstarg, scope_w, signature, defaults_w=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,
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):
return "msg"
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.get_w_value(space) == "foo() msg"
开发者ID:,项目名称:,代码行数:54,代码来源:
示例9: test_create
def test_create(self):
space = DummySpace()
args_w = []
args = Arguments(space, args_w)
assert args.arguments_w is args_w
assert args.keywords is None
assert args.keywords_w is None
assert args.firstarg() is None
args = Arguments(space, args_w, w_stararg=["*"], w_starstararg={"k": 1})
assert args.arguments_w == ["*"]
assert args.keywords == ["k"]
assert args.keywords_w == [1]
assert args.firstarg() == "*"
开发者ID:,项目名称:,代码行数:16,代码来源:
示例10: call_args_expand
def call_args_expand(hop, takes_kwds = True):
hop = hop.copy()
from pypy.interpreter.argument import Arguments
arguments = Arguments.fromshape(None, hop.args_s[1].const, # shape
range(hop.nb_args-2))
if arguments.w_starstararg is not None:
raise TyperError("**kwds call not implemented")
if arguments.w_stararg is not None:
# expand the *arg in-place -- it must be a tuple
from pypy.rpython.rtuple import AbstractTupleRepr
if arguments.w_stararg != hop.nb_args - 3:
raise TyperError("call pattern too complex")
hop.nb_args -= 1
v_tuple = hop.args_v.pop()
s_tuple = hop.args_s.pop()
r_tuple = hop.args_r.pop()
if not isinstance(r_tuple, AbstractTupleRepr):
raise TyperError("*arg must be a tuple")
for i in range(len(r_tuple.items_r)):
v_item = r_tuple.getitem_internal(hop.llops, v_tuple, i)
hop.nb_args += 1
hop.args_v.append(v_item)
hop.args_s.append(s_tuple.items[i])
hop.args_r.append(r_tuple.items_r[i])
kwds = arguments.kwds_w or {}
if not takes_kwds and kwds:
raise TyperError("kwds args not supported")
# prefix keyword arguments with 'i_'
kwds_i = {}
for key, index in kwds.items():
kwds_i['i_'+key] = index
return hop, kwds_i
开发者ID:AishwaryaKM,项目名称:python-tutorial,代码行数:34,代码来源:rbuiltin.py
示例11: checkmodule
def checkmodule(modname, backend, interactive=False, basepath='pypy.module'):
"Compile a fake PyPy module."
from pypy.objspace.fake.objspace import FakeObjSpace, W_Object
from pypy.translator.driver import TranslationDriver
space = FakeObjSpace()
space.config.translating = True
ModuleClass = __import__(basepath + '.%s' % modname,
None, None, ['Module']).Module
module = ModuleClass(space, space.wrap(modname))
w_moduledict = module.getdict(space)
gateways = find_gateways(modname, basepath, module)
functions = [gw.__spacebind__(space) for gw in gateways]
arguments = Arguments.frompacked(space, W_Object(), W_Object())
dummy_function = copy(functions[0])
def main(argv): # use the standalone mode not to allow SomeObject
dummy_rpython(dummy_function)
for func in functions:
func.call_args(arguments)
return 0
patch_pypy()
driver = TranslationDriver()
driver.setup(main, None)
try:
driver.proceed(['compile_' + backend])
except SystemExit:
raise
except:
if not interactive:
raise
debug(driver)
raise SystemExit(1)
开发者ID:gorakhargosh,项目名称:pypy,代码行数:35,代码来源:checkmodule.py
示例12: test_topacked_frompacked
def test_topacked_frompacked(self):
space = DummySpace()
args = Arguments(space, [1], ["a", "b"], [2, 3])
w_args, w_kwds = args.topacked()
assert w_args == (1,)
assert w_kwds == {"a": 2, "b": 3}
args1 = Arguments.frompacked(space, w_args, w_kwds)
assert args.arguments_w == [1]
assert set(args.keywords) == set(["a", "b"])
assert args.keywords_w[args.keywords.index("a")] == 2
assert args.keywords_w[args.keywords.index("b")] == 3
args = Arguments(space, [1])
w_args, w_kwds = args.topacked()
assert w_args == (1,)
assert not w_kwds
开发者ID:,项目名称:,代码行数:16,代码来源:
示例13: call_many_to_one
def call_many_to_one(space, shape, func, res_dtype, in_args, out):
# out must hav been built. func needs no calc_type, is usually an
# external ufunc
nin = len(in_args)
in_iters = [None] * nin
in_states = [None] * nin
for i in range(nin):
in_i = in_args[i]
assert isinstance(in_i, W_NDimArray)
in_iter, in_state = in_i.create_iter(shape)
in_iters[i] = in_iter
in_states[i] = in_state
shapelen = len(shape)
assert isinstance(out, W_NDimArray)
out_iter, out_state = out.create_iter(shape)
vals = [None] * nin
while not out_iter.done(out_state):
call_many_to_one_driver.jit_merge_point(shapelen=shapelen, func=func,
res_dtype=res_dtype, nin=nin)
for i in range(nin):
vals[i] = in_iters[i].getitem(in_states[i])
w_arglist = space.newlist(vals)
w_out_val = space.call_args(func, Arguments.frompacked(space, w_arglist))
out_iter.setitem(out_state, res_dtype.coerce(space, w_out_val))
for i in range(nin):
in_states[i] = in_iters[i].next(in_states[i])
out_state = out_iter.next(out_state)
return out
开发者ID:Qointum,项目名称:pypy,代码行数:28,代码来源:loop.py
示例14: build_args
def build_args(self, op, args_s):
space = RPythonCallsSpace()
if op == "simple_call":
return Arguments(space, list(args_s))
elif op == "call_args":
return Arguments.fromshape(space, args_s[0].const, # shape
list(args_s[1:]))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:7,代码来源:bookkeeper.py
示例15: test_blindargs
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)
开发者ID:,项目名称:,代码行数:17,代码来源:
示例16: op_call_args
def op_call_args(self):
a = self.argnames
shape = self.op.args[1].value
args = Arguments.fromshape(None, shape, a[2:])
lst = args.arguments_w[:]
for key, value in args.kwds_w.items():
lst.append("%s=%s" % (key, value))
if args.w_stararg is not None:
lst.append("*%s" % args.w_stararg)
if args.w_starstararg is not None:
lst.append("**%s" % args.w_starstararg)
return "%s = %s(%s)" % (self.resultname, a[0], ", ".join(lst))
开发者ID:TheDunn,项目名称:flex-pypy,代码行数:12,代码来源:genpyrex.py
示例17: test_args_parsing
def test_args_parsing(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 = args.parse_obj(None, "foo", Signature(["a", "b"], None, None))
assert len(calls) == 1
assert calls[0] == (None, [None, None], ["a", "b"], False, False,
[], 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,
[], 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"], 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"], 1)
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_obj, "obj", "foo",
Signature(["a", "b"], None, None))
assert excinfo.value.w_type is TypeError
assert excinfo.value._w_value == "msg foo"
开发者ID:alkorzt,项目名称:pypy,代码行数:55,代码来源:test_argument.py
示例18: call_many_to_many
def call_many_to_many(space, shape, func, in_dtypes, out_dtypes, in_args, out_args):
# out must hav been built. func needs no calc_type, is usually an
# external ufunc
nin = len(in_args)
in_iters = [None] * nin
in_states = [None] * nin
nout = len(out_args)
out_iters = [None] * nout
out_states = [None] * nout
for i in range(nin):
in_i = in_args[i]
assert isinstance(in_i, W_NDimArray)
in_iter, in_state = in_i.create_iter(shape)
in_iters[i] = in_iter
in_states[i] = in_state
for i in range(nout):
out_i = out_args[i]
assert isinstance(out_i, W_NDimArray)
out_iter, out_state = out_i.create_iter(shape)
out_iters[i] = out_iter
out_states[i] = out_state
shapelen = len(shape)
vals = [None] * nin
test_iter, test_state = in_iters[-1], in_states[-1]
if nout > 0:
test_iter, test_state = out_iters[0], out_states[0]
while not test_iter.done(test_state):
call_many_to_many_driver.jit_merge_point(shapelen=shapelen, func=func,
in_dtypes=in_dtypes, out_dtypes=out_dtypes,
nin=nin, nout=nout)
for i in range(nin):
vals[i] = in_dtypes[i].coerce(space, in_iters[i].getitem(in_states[i]))
w_arglist = space.newlist(vals)
w_outvals = space.call_args(func, Arguments.frompacked(space, w_arglist))
# w_outvals should be a tuple, but func can return a single value as well
if space.isinstance_w(w_outvals, space.w_tuple):
batch = space.listview(w_outvals)
for i in range(len(batch)):
out_iters[i].setitem(out_states[i], out_dtypes[i].coerce(space, batch[i]))
out_states[i] = out_iters[i].next(out_states[i])
elif nout > 0:
out_iters[0].setitem(out_states[0], out_dtypes[0].coerce(space, w_outvals))
out_states[0] = out_iters[0].next(out_states[0])
for i in range(nin):
in_states[i] = in_iters[i].next(in_states[i])
test_state = test_iter.next(test_state)
return space.newtuple([convert_to_array(space, o) for o in out_args])
开发者ID:abhinavthomas,项目名称:pypy,代码行数:47,代码来源:loop.py
示例19: descr__setstate__
def descr__setstate__(self, space, w_args):
w_flags, w_state, w_thunk, w_parent = space.unpackiterable(w_args,
expected_length=4)
self.flags = space.int_w(w_flags)
if space.is_w(w_parent, space.w_None):
w_parent = self.w_getmain(space)
self.parent = space.interp_w(AppCoroutine, w_parent)
ec = self.space.getexecutioncontext()
self.subctx.setstate(space, w_state)
if space.is_w(w_thunk, space.w_None):
if space.is_w(w_state, space.w_None):
self.thunk = None
else:
self.bind(_ResumeThunk(space, self.costate, self.subctx.topframe))
else:
w_func, w_args, w_kwds = space.unpackiterable(w_thunk,
expected_length=3)
args = Arguments.frompacked(space, w_args, w_kwds)
self.bind(_AppThunk(space, self.costate, w_func, args))
开发者ID:gorakhargosh,项目名称:pypy,代码行数:19,代码来源:interp_coroutine.py
示例20: test_starstarargs_special
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
开发者ID:Qointum,项目名称:pypy,代码行数:48,代码来源:test_argument.py
注:本文中的pypy.interpreter.argument.Arguments类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论