Commit b3547987 authored by Robert Bradshaw's avatar Robert Bradshaw

local merge

parents ae73725a 988c3f64
__doc__ = """
>>> spam = Spam()
>>> b,c,d,e,f,g,h,k = spam.b,spam.c,spam.d,spam.e,spam.f,spam.g,spam.h,spam.k
>>> b(1,2,3)
>>> b(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes exactly 4 arguments (5 given)
>>> c(1,2)
>>> c(1,2,3)
>>> c(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes at most 4 arguments (5 given)
>>> d(1,2)
>>> d(1,2, c=1)
>>> d(1,2,3)
Traceback (most recent call last):
TypeError: function takes at most 3 positional arguments (4 given)
>>> d(1,2, d=1)
Traceback (most recent call last):
TypeError: 'd' is an invalid keyword argument for this function
>>> e(1,2)
>>> e(1,2, c=1)
>>> e(1,2, d=1)
>>> e(1,2, c=1, d=2, e=3)
>>> e(1,2,3)
>>> e(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes at most 4 positional arguments (5 given)
>>> f(1,2, c=1)
>>> f(1,2, c=1, d=2)
>>> f(1,2,3)
Traceback (most recent call last):
TypeError: function takes at most 3 positional arguments (4 given)
>>> f(1,2)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
>>> f(1,2, c=1, e=2)
Traceback (most recent call last):
TypeError: 'e' is an invalid keyword argument for this function
>>> g(1,2, c=1, f=2)
>>> g(1,2, c=1, e=0, f=2, d=11)
>>> g(1,2, c=1, f=2, e=0, x=25)
>>> g(1,2,3)
Traceback (most recent call last):
TypeError: function takes at most 3 positional arguments (4 given)
>>> g(1,2)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
>>> g(1,2, c=1)
Traceback (most recent call last):
TypeError: required keyword argument 'f' is missing
>>> h(1,2, c=1, f=2)
>>> h(1,2, c=1, f=2, e=3)
>>> h(1,2,3,4,5,6, c=1, f=2)
>>> h(1,2,3,4,5,6, c=1, f=2, e=3, x=25, y=11)
>>> h(1,2,3)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
>>> h(1,2, d=1)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
>>> k(1,2, c=1, f=2)
>>> k(1,2, c=1, f=2, e=3)
>>> k(1,2,3,4,5,6, d=1, f=2)
>>> k(1,2,3,4,5,6, d=1, f=2, e=3, x=25, y=11)
>>> k(1,2,3)
Traceback (most recent call last):
TypeError: required keyword argument 'f' is missing
>>> k(1,2, d=1)
Traceback (most recent call last):
TypeError: required keyword argument 'f' is missing
"""
class Spam:
def b(self, a, b, c):
pass
def c(self, a, b, c=1):
pass
def d(self, a, b, *, c = 88):
pass
def e(self, a, b, c = 88, **kwds):
pass
def f(self, a, b, *, c, d = 42):
pass
def g(self, a, b, *, c, d = 42, e = 17, f, **kwds):
pass
def h(self, a, b, *args, c, d = 42, e = 17, f, **kwds):
pass
def k(self, a, b, c=1, *args, d = 42, e = 17, f, **kwds):
pass
__doc__ = """
>>> c()
120
>>> i()
42
>>> l()
666
>>> f()
12.5
>>> s()
'spam'
>>> two()
2
>>> five()
5
>>> true()
True
>>> false()
False
"""
DEF TUPLE = (1, 2, "buckle my shoe")
DEF TRUE_FALSE = (True, False)
DEF CHAR = c'x'
DEF INT = 42
DEF LONG = 666L
DEF FLOAT = 17.88
DEF FLOAT = 12.5
DEF STR = "spam"
DEF TUPLE = (1, 2, "buckle my shoe")
DEF TWO = TUPLE[1]
DEF FIVE = TWO + 3
DEF TRUE = TRUE_FALSE[0]
DEF FALSE = TRUE_FALSE[1]
cdef void f():
def c():
cdef char c
cdef int i
cdef long l
cdef float f
cdef char *s
cdef int two
cdef int five
c = CHAR
return c
def i():
cdef int i
i = INT
return i
def l():
cdef long l
l = LONG
return l
def f():
cdef float f
f = FLOAT
return f
def s():
cdef char *s
s = STR
return s
# this does not work!
#def t():
# cdef object t
# t = TUPLE
# return t
def two():
cdef int two
two = TWO
return two
def five():
cdef int five
five = FIVE
\ No newline at end of file
return five
def true():
cdef bint true
true = TRUE
return true
def false():
cdef bint false
false = FALSE
return false
__doc__ = """
>>> f()
1
>>> g()
2
>>> h()
3
"""
DEF NO = 0
DEF YES = 1
cdef void f():
def f():
cdef int i
IF YES:
i = 1
......@@ -9,8 +18,9 @@ cdef void f():
i = 2
ELSE:
i = 3
return i
cdef void g():
def g():
cdef int i
IF NO:
i = 1
......@@ -18,8 +28,9 @@ cdef void g():
i = 2
ELSE:
i = 3
return i
cdef void h():
def h():
cdef int i
IF NO:
i = 1
......@@ -27,3 +38,4 @@ cdef void h():
i = 2
ELSE:
i = 3
return i
__doc__ = """
>>> ext = Ext()
>>> b,c,d,e,f,g,h,k = ext.b,ext.c,ext.d,ext.e,ext.f,ext.g,ext.h,ext.k
>>> b(1,2,3)
>>> b(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (4 given)
>>> c(1,2)
>>> c(1,2,3)
>>> c(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes at most 3 arguments (4 given)
>>> d(1,2)
>>> d(1,2, c=1)
>>> d(1,2,3)
Traceback (most recent call last):
TypeError: function takes at most 2 positional arguments (3 given)
>>> d(1,2, d=1)
Traceback (most recent call last):
TypeError: 'd' is an invalid keyword argument for this function
>>> e(1,2)
>>> e(1,2, c=1)
>>> e(1,2, d=1)
>>> e(1,2, c=1, d=2, e=3)
>>> e(1,2,3)
>>> e(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes at most 3 positional arguments (4 given)
>>> f(1,2, c=1)
>>> f(1,2, c=1, d=2)
>>> f(1,2,3)
Traceback (most recent call last):
TypeError: function takes at most 2 positional arguments (3 given)
>>> f(1,2)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
>>> f(1,2, c=1, e=2)
Traceback (most recent call last):
TypeError: 'e' is an invalid keyword argument for this function
>>> g(1,2, c=1, f=2)
>>> g(1,2, c=1, e=0, f=2, d=11)
>>> g(1,2, c=1, f=2, e=0, x=25)
>>> g(1,2,3)
Traceback (most recent call last):
TypeError: function takes at most 2 positional arguments (3 given)
>>> g(1,2)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
>>> g(1,2, c=1)
Traceback (most recent call last):
TypeError: required keyword argument 'f' is missing
>>> h(1,2, c=1, f=2)
>>> h(1,2, c=1, f=2, e=3)
>>> h(1,2,3,4,5,6, c=1, f=2)
>>> h(1,2,3,4,5,6, c=1, f=2, e=3, x=25, y=11)
>>> h(1,2,3)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
>>> h(1,2, d=1)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
>>> k(1,2, c=1, f=2)
>>> k(1,2, c=1, f=2, e=3)
>>> k(1,2,3,4,5,6, d=1, f=2)
>>> k(1,2,3,4,5,6, d=1, f=2, e=3, x=25, y=11)
>>> k(1,2,3)
Traceback (most recent call last):
TypeError: required keyword argument 'f' is missing
>>> k(1,2, d=1)
Traceback (most recent call last):
TypeError: required keyword argument 'f' is missing
"""
cdef class Ext:
def b(self, a, b, c):
pass
def c(self, a, b, c=1):
pass
def d(self, a, b, *, c = 88):
pass
def e(self, a, b, c = 88, **kwds):
pass
def f(self, a, b, *, c, d = 42):
pass
def g(self, a, b, *, c, d = 42, e = 17, f, **kwds):
pass
def h(self, a, b, *args, c, d = 42, e = 17, f, **kwds):
pass
def k(self, a, b, c=1, *args, d = 42, e = 17, f, **kwds):
pass
__doc__ = """
>>> s = Silly(1,2,3, 'test')
>>> (spam,grail,swallow,creosote,onlyt,onlyk,tk) = (
... s.spam,s.grail,s.swallow,s.creosote,s.onlyt,s.onlyk,s.tk)
>>> s.spam(1,2,3)
>>> s.spam(1,2)
>>> spam(1,2,3)
(1, 2, 3)
>>> spam(1,2)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (2 given)
>>> s.spam(1,2,3,4)
>>> spam(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (4 given)
>>> s.spam(1,2,3, a=1)
>>> spam(1,2,3, a=1)
Traceback (most recent call last):
TypeError: 'a' is an invalid keyword argument for this function
>>> s.grail(1,2,3)
>>> s.grail(1,2,3,4)
>>> s.grail(1,2,3,4,5,6,7,8,9)
>>> s.grail(1,2)
>>> grail(1,2,3)
(1, 2, 3, ())
>>> grail(1,2,3,4)
(1, 2, 3, (4,))
>>> grail(1,2,3,4,5,6,7,8,9)
(1, 2, 3, (4, 5, 6, 7, 8, 9))
>>> grail(1,2)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (2 given)
>>> s.grail(1,2,3, a=1)
>>> grail(1,2,3, a=1)
Traceback (most recent call last):
TypeError: 'a' is an invalid keyword argument for this function
>>> s.swallow(1,2,3)
>>> s.swallow(1,2,3,4)
>>> swallow(1,2,3)
(1, 2, 3, ())
>>> swallow(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes at most 3 positional arguments (4 given)
>>> s.swallow(1,2,3, a=1, b=2)
>>> s.swallow(1,2,3, x=1)
>>> swallow(1,2,3, a=1, b=2)
(1, 2, 3, (('a', 1), ('b', 2)))
>>> swallow(1,2,3, x=1)
Traceback (most recent call last):
TypeError: keyword parameter 'x' was given by position and by name
>>> s.creosote(1,2,3)
>>> s.creosote(1,2,3,4)
>>> s.creosote(1,2,3, a=1)
>>> s.creosote(1,2,3,4, a=1, b=2)
>>> s.creosote(1,2,3,4, x=1)
>>> creosote(1,2,3)
(1, 2, 3, (), ())
>>> creosote(1,2,3,4)
(1, 2, 3, (4,), ())
>>> creosote(1,2,3, a=1)
(1, 2, 3, (), (('a', 1),))
>>> creosote(1,2,3,4, a=1, b=2)
(1, 2, 3, (4,), (('a', 1), ('b', 2)))
>>> creosote(1,2,3,4, x=1)
Traceback (most recent call last):
TypeError: keyword parameter 'x' was given by position and by name
>>> onlyt(1)
(1,)
>>> onlyt(1,2)
(1, 2)
>>> onlyt(a=1)
Traceback (most recent call last):
TypeError: 'a' is an invalid keyword argument for this function
>>> onlyt(1, a=2)
Traceback (most recent call last):
TypeError: 'a' is an invalid keyword argument for this function
>>> onlyk(a=1)
(('a', 1),)
>>> onlyk(a=1, b=2)
(('a', 1), ('b', 2))
>>> onlyk(1)
Traceback (most recent call last):
TypeError: function takes at most 0 positional arguments (1 given)
>>> onlyk(1, 2)
Traceback (most recent call last):
TypeError: function takes at most 0 positional arguments (2 given)
>>> onlyk(1, a=1, b=2)
Traceback (most recent call last):
TypeError: function takes at most 0 positional arguments (1 given)
>>> tk(a=1)
(('a', 1),)
>>> tk(a=1, b=2)
(('a', 1), ('b', 2))
>>> tk(1)
(1,)
>>> tk(1, 2)
(1, 2)
>>> tk(1, a=1, b=2)
(1, ('a', 1), ('b', 2))
"""
cdef sorteditems(d):
l = d.items()
l.sort()
return tuple(l)
cdef class Silly:
def __init__(self, *a):
pass
def spam(self, x, y, z):
pass
return (x, y, z)
def grail(self, x, y, z, *a):
pass
return (x, y, z, a)
def swallow(self, x, y, z, **k):
pass
return (x, y, z, sorteditems(k))
def creosote(self, x, y, z, *a, **k):
pass
return (x, y, z, a, sorteditems(k))
def onlyt(self, *a):
return a
def onlyk(self, **k):
return sorteditems(k)
def tk(self, *a, **k):
return a + sorteditems(k)
__doc__ = """
>>> test_and(None, None)
True
>>> test_and(None, 1)
False
>>> test_and(1, None)
False
>>> test_more(None, None)
True
>>> test_more(None, 1)
True
>>> test_more(1, None)
False
>>> test_more(None, 0)
False
>>> test_more_c(None, None)
True
>>> test_more_c(None, 1)
True
>>> test_more_c(1, None)
False
>>> test_more_c(None, 0)
False
"""
def test_and(a,b):
return a is None and b is None
def test_more(a,b):
return a is None and (b is None or b == 1)
def test_more_c(a,b):
return (a is None or 1 == 2) and (b is None or b == 1)
__doc__ = """
>>> d = {1 : 2}
>>> test(**d)
Traceback (most recent call last):
TypeError: test() keywords must be strings
>>> d
{1: 2}
>>> d = {}
>>> test(**d)
{'arg': 3}
>>> d
{}
>>> d = {'arg' : 2}
>>> test(**d)
{'arg': 3}
>>> d
{'arg': 2}
"""
def test(**kw):
kw['arg'] = 3
return kw
......@@ -67,6 +67,18 @@ __doc__ = """
>>> h(1,2, d=1)
Traceback (most recent call last):
TypeError: required keyword argument 'c' is missing
>>> k(1,2, c=1, f=2)
>>> k(1,2, c=1, f=2, e=3)
>>> k(1,2,3,4,5,6, d=1, f=2)
>>> k(1,2,3,4,5,6, d=1, f=2, e=3, x=25, y=11)
>>> k(1,2,3)
Traceback (most recent call last):
TypeError: required keyword argument 'f' is missing
>>> k(1,2, d=1)
Traceback (most recent call last):
TypeError: required keyword argument 'f' is missing
"""
def b(a, b, c):
......@@ -89,3 +101,6 @@ def g(a, b, *, c, d = 42, e = 17, f, **kwds):
def h(a, b, *args, c, d = 42, e = 17, f, **kwds):
pass
def k(a, b, c=1, *args, d = 42, e = 17, f, **kwds):
pass
......@@ -15,7 +15,9 @@ __doc__ = """
>>> test(sys.maxint * 2 + 1)
4294967295L
>>> test(8 ** unsigned_long_size() - 1) > sys.maxint
>>> test(256 ** unsigned_long_size() - 1) > 0
True
>>> test(256 ** unsigned_long_size() - 1) > sys.maxint
True
"""
......
__doc__ = """
>>> spam(1,2,3)
(1, 2, 3)
>>> spam(1,2)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (2 given)
......@@ -11,8 +12,11 @@ __doc__ = """
TypeError: 'a' is an invalid keyword argument for this function
>>> grail(1,2,3)
(1, 2, 3, ())
>>> grail(1,2,3,4)
(1, 2, 3, (4,))
>>> grail(1,2,3,4,5,6,7,8,9)
(1, 2, 3, (4, 5, 6, 7, 8, 9))
>>> grail(1,2)
Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (2 given)
......@@ -21,31 +25,87 @@ __doc__ = """
TypeError: 'a' is an invalid keyword argument for this function
>>> swallow(1,2,3)
(1, 2, 3, ())
>>> swallow(1,2,3,4)
Traceback (most recent call last):
TypeError: function takes at most 3 positional arguments (4 given)
>>> swallow(1,2,3, a=1, b=2)
(1, 2, 3, (('a', 1), ('b', 2)))
>>> swallow(1,2,3, x=1)
Traceback (most recent call last):
TypeError: keyword parameter 'x' was given by position and by name
>>> creosote(1,2,3)
(1, 2, 3, (), ())
>>> creosote(1,2,3,4)
(1, 2, 3, (4,), ())
>>> creosote(1,2,3, a=1)
(1, 2, 3, (), (('a', 1),))
>>> creosote(1,2,3,4, a=1, b=2)
(1, 2, 3, (4,), (('a', 1), ('b', 2)))
>>> creosote(1,2,3,4, x=1)
Traceback (most recent call last):
TypeError: keyword parameter 'x' was given by position and by name
>>> onlyt(1)
(1,)
>>> onlyt(1,2)
(1, 2)
>>> onlyt(a=1)
Traceback (most recent call last):
TypeError: 'a' is an invalid keyword argument for this function
>>> onlyt(1, a=2)
Traceback (most recent call last):
TypeError: 'a' is an invalid keyword argument for this function
>>> onlyk(a=1)
(('a', 1),)
>>> onlyk(a=1, b=2)
(('a', 1), ('b', 2))
>>> onlyk(1)
Traceback (most recent call last):
TypeError: function takes at most 0 positional arguments (1 given)
>>> onlyk(1, 2)
Traceback (most recent call last):
TypeError: function takes at most 0 positional arguments (2 given)
>>> onlyk(1, a=1, b=2)
Traceback (most recent call last):
TypeError: function takes at most 0 positional arguments (1 given)
>>> tk(a=1)
(('a', 1),)
>>> tk(a=1, b=2)
(('a', 1), ('b', 2))
>>> tk(1)
(1,)
>>> tk(1, 2)
(1, 2)
>>> tk(1, a=1, b=2)
(1, ('a', 1), ('b', 2))
"""
cdef sorteditems(d):
l = d.items()
l.sort()
return tuple(l)
def spam(x, y, z):
pass
return (x, y, z)
def grail(x, y, z, *a):
pass
return (x, y, z, a)
def swallow(x, y, z, **k):
pass
return (x, y, z, sorteditems(k))
def creosote(x, y, z, *a, **k):
pass
return (x, y, z, a, sorteditems(k))
def onlyt(*a):
return a
def onlyk(**k):
return sorteditems(k)
def tk(*a, **k):
return a + sorteditems(k)
__doc__ = """
>>> unpack_normal([1,2])
(1, 2)
>>> unpack_normal([1,2,3])
Traceback (most recent call last):
ValueError: too many values to unpack
>>> unpack_comp([1,2])
(1, 2)
>>> unpack_comp([1,2,3])
Traceback (most recent call last):
ValueError: too many values to unpack
>>> unpack_expr([1,2])
(1, 2)
>>> unpack_expr([1,2,3])
Traceback (most recent call last):
ValueError: too many values to unpack
"""
def unpack_normal(l):
a,b = l
return a,b
def unpack_comp(l):
a,b = [ n for n in l ]
return a,b
def unpack_expr(l):
a,b = [ n*n for n in l ]
return a,b
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment