Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
9c7d4b13
Commit
9c7d4b13
authored
Jul 25, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adapt Py2-only 'raise' statements to Py2/Py3
parent
fd4ba3c5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
15 deletions
+60
-15
Cython/Tempita/_tempita.py
Cython/Tempita/_tempita.py
+6
-12
pyximport/pyximport.py
pyximport/pyximport.py
+7
-3
tests/pyximport/pyximport_errors.srctree
tests/pyximport/pyximport_errors.srctree
+47
-0
No files found.
Cython/Tempita/_tempita.py
View file @
9c7d4b13
...
...
@@ -302,28 +302,24 @@ class Template(object):
raise SyntaxError(
'
invalid
syntax
in
expression
:
%
s
' % code)
return value
except:
exc_info = sys.exc_info()
e = exc_info[1]
except Exception as e:
if getattr(e, '
args
', None):
arg0 = e.args[0]
else:
arg0 = coerce_text(e)
e.args = (self._add_line_info(arg0, pos),)
raise
exc_info[0], e, exc_info[2]
raise
def _exec(self, code, ns, pos):
__traceback_hide__ = True
try:
exec(code, self.default_namespace, ns)
except:
exc_info = sys.exc_info()
e = exc_info[1]
except Exception as e:
if e.args:
e.args = (self._add_line_info(e.args[0], pos),)
else:
e.args = (self._add_line_info(None, pos),)
raise
exc_info[0], e, exc_info[2]
raise
def _repr(self, value, pos):
__traceback_hide__ = True
...
...
@@ -341,11 +337,9 @@ class Template(object):
if (is_unicode(value)
and self.default_encoding):
value = value.encode(self.default_encoding)
except:
exc_info = sys.exc_info()
e = exc_info[1]
except Exception as e:
e.args = (self._add_line_info(e.args[0], pos),)
raise
exc_info[0], e, exc_info[2]
raise
else:
if self._unicode and isinstance(value, bytes):
if not self.default_encoding:
...
...
pyximport/pyximport.py
View file @
9c7d4b13
...
...
@@ -217,10 +217,14 @@ def load_module(name, pyxfilename, pyxbuild_dir=None, is_package=False,
mod
=
imp
.
load_source
(
name
,
pyxfilename
)
assert
mod
.
__file__
in
(
pyxfilename
,
pyxfilename
+
'c'
,
pyxfilename
+
'o'
),
(
mod
.
__file__
,
pyxfilename
)
else
:
tb
=
sys
.
exc_info
()[
2
]
import
traceback
raise
ImportError
(
"Building module %s failed: %s"
%
(
name
,
traceback
.
format_exception_only
(
*
sys
.
exc_info
()[:
2
]))),
None
,
sys
.
exc_info
()[
2
]
exc
=
ImportError
(
"Building module %s failed: %s"
%
(
name
,
traceback
.
format_exception_only
(
*
sys
.
exc_info
()[:
2
])))
if
sys
.
version_info
[
0
]
>=
3
:
raise
exc
.
with_traceback
(
tb
)
else
:
exec
(
"raise exc, None, tb"
,
{
'exc'
:
exc
,
'tb'
:
tb
})
return
mod
...
...
tests/pyximport/pyximport_errors.srctree
0 → 100644
View file @
9c7d4b13
PYTHON -c "import pyximport_test; pyximport_test.test()"
######## pyximport_test.py ########
import os.path
from contextlib import contextmanager
import pyximport
pyximport.install(build_dir=os.path.join(os.path.dirname(__file__), "BUILD"))
@contextmanager
def fails(exc=ImportError):
try:
yield
except exc:
pass
else:
raise RuntimeError("NOT RAISED!")
def test():
with fails():
import compiler_error
with fails():
import syntax_error
with fails():
import runtime_error
######## compiler_error.pyx ########
from __future__ import braces
######## syntax_error.pyx ########
def test {
BRACES!
}
######## runtime_error.pyx ########
raise ValueError()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment