Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r71251:f66d67cc5297
Date: 2014-05-04 01:33 +0100
http://bitbucket.org/pypy/pypy/changeset/f66d67cc5297/
Log: modernise raise syntax
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -593,7 +593,7 @@
def can_enter_jit(_self, **livevars):
if _self.autoreds:
- raise TypeError, "Cannot call can_enter_jit on a driver with
reds='auto'"
+ raise TypeError("Cannot call can_enter_jit on a driver with
reds='auto'")
# special-cased by ExtRegistryEntry
if _self.check_untranslated:
_self._check_arguments(livevars, False)
diff --git a/rpython/rlib/libffi.py b/rpython/rlib/libffi.py
--- a/rpython/rlib/libffi.py
+++ b/rpython/rlib/libffi.py
@@ -109,11 +109,11 @@
def _check_type(TYPE):
if isinstance(TYPE, lltype.Ptr):
if TYPE.TO._gckind != 'raw':
- raise TypeError, "Can only push raw values to C, not 'gc'"
+ raise TypeError("Can only push raw values to C, not 'gc'")
# XXX probably we should recursively check for struct fields here,
# lets just ignore that for now
if isinstance(TYPE.TO, lltype.Array) and 'nolength' not in
TYPE.TO._hints:
- raise TypeError, "Can only push to C arrays without length info"
+ raise TypeError("Can only push to C arrays without length info")
class ArgChain(object):
@@ -136,7 +136,7 @@
elif TYPE is rffi.FLOAT:
cls = SingleFloatArg
else:
- raise TypeError, 'Unsupported argument type: %s' % TYPE
+ raise TypeError('Unsupported argument type: %s' % TYPE)
self._append(cls(val))
return self
@@ -247,8 +247,8 @@
# assuming that argchain is completely virtual.
self = jit.promote(self)
if argchain.numargs != len(self.argtypes):
- raise TypeError, 'Wrong number of arguments: %d expected, got %d'
%\
- (len(self.argtypes), argchain.numargs)
+ raise TypeError('Wrong number of arguments: %d expected, got %d' %
+ (len(self.argtypes), argchain.numargs))
ll_args = self._prepare()
i = 0
arg = argchain.first
@@ -273,7 +273,7 @@
elif RESULT is lltype.Void:
return self._do_call_void(self.funcsym, ll_args)
else:
- raise TypeError, 'Unsupported result type: %s' % RESULT
+ raise TypeError('Unsupported result type: %s' % RESULT)
#
return rffi.cast(RESULT, res)
@@ -430,7 +430,7 @@
def getpointer_by_ordinal(self, name, argtypes, restype,
flags=FUNCFLAG_CDECL):
- return Func('by_ordinal', argtypes, restype,
+ return Func('by_ordinal', argtypes, restype,
dlsym_byordinal(self.lib, name),
flags=flags, keepalive=self)
def getaddressindll(self, name):
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -122,7 +122,7 @@
"""
typecheck = kwds.pop('typecheck', True)
if types_ and kwds:
- raise TypeError, 'Cannot mix positional arguments and keywords'
+ raise TypeError('Cannot mix positional arguments and keywords')
if not typecheck:
def decorator(f):
@@ -177,7 +177,7 @@
if not s_expected.contains(s_argtype):
msg = "%s argument %r must be of type %s" % (
f.func_name, srcargs[i], expected_type)
- raise TypeError, msg
+ raise TypeError(msg)
#
template = """
def {name}({arglist}):
@@ -576,7 +576,7 @@
# ____________________________________________________________
def hlinvoke(repr, llcallable, *args):
- raise TypeError, "hlinvoke is meant to be rtyped and not called direclty"
+ raise TypeError("hlinvoke is meant to be rtyped and not called direclty")
def invoke_around_extcall(before, after):
"""Call before() before any external function call, and after() after.
diff --git a/rpython/rlib/rarithmetic.py b/rpython/rlib/rarithmetic.py
--- a/rpython/rlib/rarithmetic.py
+++ b/rpython/rlib/rarithmetic.py
@@ -173,7 +173,7 @@
if type(r) is long and not is_valid_int(r):
# checks only if applicable to r's type.
# this happens in the garbage collector.
- raise OverflowError, "signed integer expression did overflow"
+ raise OverflowError("signed integer expression did overflow")
return r
# Strange things happening for float to int on 64 bit:
@@ -213,7 +213,7 @@
return other_type
if self_type.SIGNED == other_type.SIGNED:
return build_int(None, self_type.SIGNED, max(self_type.BITS,
other_type.BITS))
- raise AssertionError, "Merging these types (%s, %s) is not supported" %
(self_type, other_type)
+ raise AssertionError("Merging these types (%s, %s) is not supported" %
(self_type, other_type))
def signedtype(t):
if t in (bool, int, long):
diff --git a/rpython/rlib/rsre/rpy/sre_compile.py
b/rpython/rlib/rsre/rpy/sre_compile.py
--- a/rpython/rlib/rsre/rpy/sre_compile.py
+++ b/rpython/rlib/rsre/rpy/sre_compile.py
@@ -63,7 +63,7 @@
emit(OPCODES[ANY])
elif op in REPEATING_CODES:
if flags & SRE_FLAG_TEMPLATE:
- raise error, "internal: unsupported template operator"
+ raise error("internal: unsupported template operator")
emit(OPCODES[REPEAT])
skip = _len(code); emit(0)
emit(av[0])
@@ -112,7 +112,7 @@
else:
lo, hi = av[1].getwidth()
if lo != hi:
- raise error, "look-behind requires fixed-width pattern"
+ raise error("look-behind requires fixed-width pattern")
emit(lo) # look behind
_compile(code, av[1], flags)
emit(OPCODES[SUCCESS])
@@ -173,7 +173,7 @@
else:
code[skipyes] = _len(code) - skipyes + 1
else:
- raise ValueError, ("unsupported operand type", op)
+ raise ValueError("unsupported operand type", op)
def _compile_charset(charset, flags, code, fixup=None):
# compile charset subprogram
@@ -201,7 +201,7 @@
else:
emit(CHCODES[av])
else:
- raise error, "internal: unsupported set operator"
+ raise error("internal: unsupported set operator")
emit(OPCODES[FAILURE])
def _optimize_charset(charset, fixup):
diff --git a/rpython/rlib/rsre/rpy/sre_parse.py
b/rpython/rlib/rsre/rpy/sre_parse.py
--- a/rpython/rlib/rsre/rpy/sre_parse.py
+++ b/rpython/rlib/rsre/rpy/sre_parse.py
@@ -75,7 +75,7 @@
if name is not None:
ogid = self.groupdict.get(name, None)
if ogid is not None:
- raise error, ("redefinition of group name %s as group %d; "
+ raise error("redefinition of group name %s as group %d; "
"was group %d" % (repr(name), gid, ogid))
self.groupdict[name] = gid
self.open.append(gid)
@@ -188,7 +188,7 @@
try:
c = self.string[self.index + 1]
except IndexError:
- raise error, "bogus escape (end of line)"
+ raise error("bogus escape (end of line)")
char = char + c
self.index = self.index + len(char)
self.next = char
@@ -238,7 +238,7 @@
escape = escape + source.get()
escape = escape[2:]
if len(escape) != 2:
- raise error, "bogus escape: %s" % repr("\\" + escape)
+ raise error("bogus escape: %s" % repr("\\" + escape))
return LITERAL, int(escape, 16) & 0xff
elif c in OCTDIGITS:
# octal escape (up to three digits)
@@ -247,12 +247,12 @@
escape = escape[1:]
return LITERAL, int(escape, 8) & 0xff
elif c in DIGITS:
- raise error, "bogus escape: %s" % repr(escape)
+ raise error("bogus escape: %s" % repr(escape))
if len(escape) == 2:
return LITERAL, ord(escape[1])
except ValueError:
pass
- raise error, "bogus escape: %s" % repr(escape)
+ raise error("bogus escape: %s" % repr(escape))
def _escape(source, escape, state):
# handle escape code in expression
@@ -289,14 +289,14 @@
group = int(escape[1:])
if group < state.groups:
if not state.checkgroup(group):
- raise error, "cannot refer to open group"
+ raise error("cannot refer to open group")
return GROUPREF, group
raise ValueError
if len(escape) == 2:
return LITERAL, ord(escape[1])
except ValueError:
pass
- raise error, "bogus escape: %s" % repr(escape)
+ raise error("bogus escape: %s" % repr(escape))
def _parse_sub(source, state, nested=1):
# parse an alternation: a|b|c
@@ -313,7 +313,7 @@
if not source.next or sourcematch(")", 0):
break
else:
- raise error, "pattern not properly closed"
+ raise error("pattern not properly closed")
if len(items) == 1:
return items[0]
@@ -362,11 +362,11 @@
if source.match("|"):
item_no = _parse(source, state)
if source.match("|"):
- raise error, "conditional backref with more than two branches"
+ raise error("conditional backref with more than two branches")
else:
item_no = None
if source.next and not source.match(")", 0):
- raise error, "pattern not properly closed"
+ raise error("pattern not properly closed")
subpattern = SubPattern(state)
subpattern.append((GROUPREF_EXISTS, (condgroup, item_yes, item_no)))
return subpattern
@@ -431,7 +431,7 @@
elif this:
code1 = LITERAL, ord(this)
else:
- raise error, "unexpected end of regular expression"
+ raise error("unexpected end of regular expression")
if sourcematch("-"):
# potential range
this = sourceget()
@@ -447,14 +447,14 @@
else:
code2 = LITERAL, ord(this)
if code1[0] != LITERAL or code2[0] != LITERAL:
- raise error, "bad character range"
+ raise error("bad character range")
lo = code1[1]
hi = code2[1]
if hi < lo:
- raise error, "bad character range"
+ raise error("bad character range")
setappend((RANGE, (lo, hi)))
else:
- raise error, "unexpected end of regular expression"
+ raise error("unexpected end of regular expression")
else:
if code1[0] is IN:
code1 = code1[1][0]
@@ -507,16 +507,16 @@
if max < min:
raise error("bad repeat interval")
else:
- raise error, "not supported"
+ raise error("not supported")
# figure out which item to repeat
if subpattern:
item = subpattern[-1:]
else:
item = None
if not item or (_len(item) == 1 and item[0][0] == AT):
- raise error, "nothing to repeat"
+ raise error("nothing to repeat")
if item[0][0] in REPEATCODES:
- raise error, "multiple repeat"
+ raise error("multiple repeat")
if sourcematch("?"):
subpattern[-1] = (MIN_REPEAT, (min, max, item))
else:
@@ -540,7 +540,7 @@
while 1:
char = sourceget()
if char is None:
- raise error, "unterminated name"
+ raise error("unterminated name")
if char == ">":
break
name = name + char
@@ -556,7 +556,7 @@
while 1:
char = sourceget()
if char is None:
- raise error, "unterminated name"
+ raise error("unterminated name")
if char == ")":
break
name = name + char
@@ -567,14 +567,14 @@
"%r" % name)
gid = state.groupdict.get(name)
if gid is None:
- raise error, "unknown group name"
+ raise error("unknown group name")
subpatternappend((GROUPREF, gid))
continue
else:
char = sourceget()
if char is None:
- raise error, "unexpected end of pattern"
- raise error, "unknown specifier: ?P%s" % char
+ raise error("unexpected end of pattern")
+ raise error("unknown specifier: ?P%s" % char)
elif sourcematch(":"):
# non-capturing group
group = 2
@@ -585,7 +585,7 @@
break
sourceget()
if not sourcematch(")"):
- raise error, "unbalanced parenthesis"
+ raise error("unbalanced parenthesis")
continue
elif source.next in ASSERTCHARS:
# lookahead assertions
@@ -593,12 +593,12 @@
dir = 1
if char == "<":
if source.next not in LOOKBEHINDASSERTCHARS:
- raise error, "syntax error"
+ raise error("syntax error")
dir = -1 # lookbehind
char = sourceget()
p = _parse_sub(source, state)
if not sourcematch(")"):
- raise error, "unbalanced parenthesis"
+ raise error("unbalanced parenthesis")
if char == "=":
subpatternappend((ASSERT, (dir, p)))
else:
@@ -610,7 +610,7 @@
while 1:
char = sourceget()
if char is None:
- raise error, "unterminated name"
+ raise error("unterminated name")
if char == ")":
break
condname = condname + char
@@ -620,16 +620,16 @@
if isname(condname):
condgroup = state.groupdict.get(condname)
if condgroup is None:
- raise error, "unknown group name"
+ raise error("unknown group name")
else:
try:
condgroup = int(condname)
except ValueError:
- raise error, "bad character in group name"
+ raise error("bad character in group name")
else:
# flags
if not source.next in FLAGS:
- raise error, "unexpected end of pattern"
+ raise error("unexpected end of pattern")
while source.next in FLAGS:
state.flags = state.flags | FLAGS[sourceget()]
if group:
@@ -644,7 +644,7 @@
else:
p = _parse_sub(source, state)
if not sourcematch(")"):
- raise error, "unbalanced parenthesis"
+ raise error("unbalanced parenthesis")
if group is not None:
state.closegroup(group)
subpatternappend((SUBPATTERN, (group, p)))
@@ -652,10 +652,10 @@
while 1:
char = sourceget()
if char is None:
- raise error, "unexpected end of pattern"
+ raise error("unexpected end of pattern")
if char == ")":
break
- raise error, "unknown extension"
+ raise error("unknown extension")
elif this == "^":
subpatternappend((AT, AT_BEGINNING))
@@ -668,7 +668,7 @@
subpatternappend(code)
else:
- raise error, "parser error"
+ raise error("parser error")
return subpattern
@@ -686,9 +686,9 @@
tail = source.get()
if tail == ")":
- raise error, "unbalanced parenthesis"
+ raise error("unbalanced parenthesis")
elif tail:
- raise error, "bogus characters at end of regular expression"
+ raise error("bogus characters at end of regular expression")
if flags & SRE_FLAG_DEBUG:
p.dump()
@@ -730,23 +730,23 @@
while 1:
char = sget()
if char is None:
- raise error, "unterminated group name"
+ raise error("unterminated group name")
if char == ">":
break
name = name + char
if not name:
- raise error, "missing group name"
+ raise error("missing group name")
try:
index = int(name)
if index < 0:
- raise error, "negative group number"
+ raise error("negative group number")
except ValueError:
if not isname(name):
- raise error, "bad character in group name"
+ raise error("bad character in group name")
try:
index = pattern.groupindex[name]
except KeyError:
- raise IndexError, "unknown group name"
+ raise IndexError("unknown group name")
a((MARK, index))
elif c == "0":
if s.next in OCTDIGITS:
@@ -796,7 +796,7 @@
for index, group in groups:
literals[index] = s = g(group)
if s is None:
- raise error, "unmatched group"
+ raise error("unmatched group")
except IndexError:
- raise error, "invalid group reference"
+ raise error("invalid group reference")
return sep.join(literals)
diff --git a/rpython/rlib/rzipfile.py b/rpython/rlib/rzipfile.py
--- a/rpython/rlib/rzipfile.py
+++ b/rpython/rlib/rzipfile.py
@@ -214,7 +214,7 @@
def _GetContents(self, fp):
endrec = _EndRecData(fp)
if not endrec:
- raise BadZipfile, "File is not a zip file"
+ raise BadZipfile("File is not a zip file")
size_cd = endrec.stuff[5] # bytes in central directory
offset_cd = endrec.stuff[6] # offset of central directory
self.comment = endrec.comment
@@ -227,7 +227,7 @@
centdir = fp.read(46)
total = total + 46
if centdir[0:4] != stringCentralDir:
- raise BadZipfile, "Bad magic number for central directory"
+ raise BadZipfile("Bad magic number for central directory")
centdir = runpack(structCentralDir, centdir)
filename = fp.read(centdir[_CD_FILENAME_LENGTH])
# Create ZipInfo instance to store file information
@@ -255,7 +255,7 @@
fp.seek(data.header_offset, 0)
fheader = fp.read(30)
if fheader[0:4] != stringFileHeader:
- raise BadZipfile, "Bad magic number for file header"
+ raise BadZipfile("Bad magic number for file header")
fheader = runpack(structFileHeader, fheader)
# file_offset is computed here, since the extra field for
# the central directory and for the local file header
@@ -266,9 +266,8 @@
+ fheader[_FH_EXTRA_FIELD_LENGTH])
fname = fp.read(fheader[_FH_FILENAME_LENGTH])
if fname != data.orig_filename:
- raise BadZipfile, \
- 'File name in directory "%s" and header "%s" differ.' % (
- data.orig_filename, fname)
+ raise BadZipfile('File name in directory "%s" and '
+ 'header "%s" differ.' % (data.orig_filename, fname))
fp.seek(self.start_dir, 0)
def getinfo(self, filename):
@@ -296,15 +295,13 @@
finally:
rzlib.inflateEnd(stream)
elif zinfo.compress_type == ZIP_DEFLATED:
- raise BadZipfile, \
- "Cannot decompress file, zlib not installed"
+ raise BadZipfile("Cannot decompress file, zlib not installed")
else:
- raise BadZipfile, \
- "Unsupported compression method %d for file %s" % \
- (zinfo.compress_type, filename)
+ raise BadZipfile("Unsupported compression method %d for "
+ "file %s" % (zinfo.compress_type, filename))
crc = crc32(bytes)
if crc != zinfo.CRC:
- raise BadZipfile, "Bad CRC-32 for file %s" % filename
+ raise BadZipfile("Bad CRC-32 for file %s" % filename)
return bytes
finally:
fp.close()
diff --git a/rpython/rlib/test/test_streamio.py
b/rpython/rlib/test/test_streamio.py
--- a/rpython/rlib/test/test_streamio.py
+++ b/rpython/rlib/test/test_streamio.py
@@ -95,7 +95,7 @@
elif whence == 2:
offset += len(self.buf)
else:
- raise ValueError, "whence should be 0, 1 or 2"
+ raise ValueError("whence should be 0, 1 or 2")
if offset < 0:
offset = 0
self.pos = offset
diff --git a/rpython/rlib/unicodedata/unicodedb_5_2_0.py
b/rpython/rlib/unicodedata/unicodedb_5_2_0.py
--- a/rpython/rlib/unicodedata/unicodedb_5_2_0.py
+++ b/rpython/rlib/unicodedata/unicodedb_5_2_0.py
@@ -39,7 +39,7 @@
charnode = left
else:
charnode = right
- raise KeyError, name
+ raise KeyError(name)
def name_of_node(charnode):
res = []
@@ -112664,7 +112664,7 @@
if code == 917505: res = 9201
if 917536 <= code <= 917631: res = _charnames_917536[code-917536]
if 917760 <= code <= 917999: res = _charnames_917760[code-917760]
- if res == -1: raise KeyError, code
+ if res == -1: raise KeyError(code)
return name_of_node(res)
# the following dictionary is used by modules that take this as a base
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit