| ★ wanayoo — archive 1999 https://github.com/ipython/ipython/pull/2064/ | Nouvelle recherche | Portail wanayoo |
|
|
Carreau |
conform to pep 3110
…
brutally replace all `exeption <type>, <name>:` by `exception <type> as <name> :` `exception <type>, <type> :` should not be present anywhere in the code anymore, or should be present with explicit tuple as `exception (<type>, <type>)` |
28b538a
|
I think these are all good, but let's run a test_pr just to be safe...
This make me think, there is a lot a "fixes" that 2to3 can apply independently to the all source tree and that will still be python2.x compatible.
Do we want to start applying them to have a smoother transition to a fully dirrectly python3 compatible version of IPython ?
I think the hardest part will be the u'strings' that are invalid python 3.1/3.2 but will be understood in python 3.3.
[edit :]
see https://github.com/Carreau/ipython/compare/2to3compat
|
|
Carreau |
fix more exeptions
…
2to3 makes a better job than regexp |
90c0a4e
|
I like this approach - I find except Exception as e much more readable than the old style. We could also skip the relevant 2to3 fixer during installation (they can be disabled individually, as seen here).
I've also been meaning to find all the files which use the ugly print >>foo syntax, and sprinkle some __future__ on them.
let's see this one as a first step.
I'll add a commit that disable exceptions in 2to3 and make another PR with what i've done so far tomorrow.
|
|
Carreau |
disable some specific 2to3 fixes whith setup.py
…
this should allow a more compatible codebase between python 2.x and 3.x |
1c49f84
|
skip except in setup.py for python3.
My python 3.2 keep trying to import nose from 2.7 site-package, so test_pr fail to test for python 3.x so if SO can run test_pr for my on python 3...
setup.py
@@ -234,6 +234,12 @@ def cleanup(): |
||
| 234 | 234 |
|
| 235 | 235 |
if PY3: |
| 236 | 236 |
setuptools_extra_args['use_2to3'] = True |
| 237 |
+ # we try to make a 2.6, 2.7, and 3.1 to 3.3 python compatible code |
|
| 238 |
+ # so we explicitely disable some 2to3 fixes to be sure we ain't forgetting |
|
| 1 |
'explicitly'. Also, "ain't" is colloquial - we should use "aren't", so that it's clear to people who're less familiar with English.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
|
|
fixed,
As a side note, I skipped IPython/deathrow and IPython/quarantine on purpose.
Thanks. Skipping deathrow and quarantine should be fine, as they don't get installed. If anyone updates those, we'll need to check they use the new style - but test_pr should pick that up.
The only other thing to consider is that we're changing external modules, especially pexpect, so we can send the changes upstream (although they might be rejected by projects which still want to support Python < 2.6).
Hum, checking again it seems like I did apply 2to3 fo deathrow and quarantine, a * might have slips through... I won't do it for the next changes.
pexpect seem to be dead for 3 years now...
I know, I had to fork it: http://pypi.python.org/pypi/pexpect-u
It looks like SSH is just an adapted example, not a real upstream package, so I think we're all OK.
Test results for commit 3f213ee merged into master
Platform: linux2
Not available for testing: python2.6
No objection from me.
Great, I've merged this.
Showing 4 unique commits by 1 author.
| Jun 30, 2012 | ||||
|---|---|---|---|---|
|
|
Carreau |
conform to pep 3110
…
brutally replace all `exeption <type>, <name>:` by `exception <type> as <name> :` `exception <type>, <type> :` should not be present anywhere in the code anymore, or should be present with explicit tuple as `exception (<type>, <type>)` |
28b538a
|
|
| Jul 01, 2012 | ||||
|---|---|---|---|---|
|
|
Carreau |
fix more exeptions
…
2to3 makes a better job than regexp |
90c0a4e
|
|
| Jul 04, 2012 | ||||
|---|---|---|---|---|
|
|
Carreau |
disable some specific 2to3 fixes whith setup.py
…
this should allow a more compatible codebase between python 2.x and 3.x |
1c49f84
|
|
|
|
Carreau |
fix english in comment
|
3f213ee
|
|
Showing 36 changed files with 83 additions and 77 deletions. Show diff stats Hide diff stats
@@ -163,19 +163,19 @@ def __setitem__(self, key, value): |
||
| 163 | 163 |
def __getattr__(self, key): |
| 164 | 164 |
try: |
| 165 | 165 |
return self.__getitem__(key) |
| 166 |
- except KeyError, e:
|
|
| 166 |
+ except KeyError as e:
|
|
| 167 | 167 |
raise AttributeError(e) |
| 168 | 168 |
|
| 169 | 169 |
def __setattr__(self, key, value): |
| 170 | 170 |
try: |
| 171 | 171 |
self.__setitem__(key, value) |
| 172 |
- except KeyError, e:
|
|
| 172 |
+ except KeyError as e:
|
|
| 173 | 173 |
raise AttributeError(e) |
| 174 | 174 |
|
| 175 | 175 |
def __delattr__(self, key): |
| 176 | 176 |
try: |
| 177 | 177 |
dict.__delitem__(self, key) |
| 178 |
- except KeyError, e:
|
|
| 178 |
+ except KeyError as e:
|
|
| 179 | 179 |
raise AttributeError(e) |
| 180 | 180 |
|
| 181 | 181 |
|
@@ -151,7 +151,7 @@ def soft_define_alias(self, name, cmd): |
||
| 151 | 151 |
"""Define an alias, but don't raise on an AliasError.""" |
| 152 | 152 |
try: |
| 153 | 153 |
self.define_alias(name, cmd) |
| 154 |
- except AliasError, e:
|
|
| 154 |
+ except AliasError as e:
|
|
| 155 | 155 |
error("Invalid alias: %s" % e)
|
| 156 | 156 |
|
| 157 | 157 |
def define_alias(self, name, cmd): |
@@ -2454,7 +2454,7 @@ def safe_execfile(self, fname, *where, **kw): |
||
| 2454 | 2454 |
with prepended_to_syspath(dname): |
| 2455 | 2455 |
try: |
| 2456 | 2456 |
py3compat.execfile(fname,*where) |
| 2457 |
- except SystemExit, status:
|
|
| 2457 |
+ except SystemExit as status:
|
|
| 2458 | 2458 |
# If the call was made with 0 or None exit status (sys.exit(0) |
| 2459 | 2459 |
# or sys.exit() ), don't bother showing a traceback, as both of |
| 2460 | 2460 |
# these are considered normal by the OS: |
@@ -584,7 +584,7 @@ def parse_options(self, arg_str, opt_str, *long_opts, **kw): |
||
| 584 | 584 |
# Do regular option processing |
| 585 | 585 |
try: |
| 586 | 586 |
opts,args = getopt(argv, opt_str, long_opts) |
| 587 |
- except GetoptError,e:
|
|
| 587 |
+ except GetoptError as e:
|
|
| 588 | 588 |
raise UsageError('%s ( allowed: "%s" %s)' % (e.msg,opt_str,
|
| 589 | 589 |
" ".join(long_opts))) |
| 590 | 590 |
for o,a in opts: |
@@ -513,7 +513,7 @@ def edit(self, parameter_s='',last_call=['','']): |
||
| 513 | 513 |
if is_temp: |
| 514 | 514 |
try: |
| 515 | 515 |
return open(filename).read() |
| 516 |
- except IOError,msg:
|
|
| 516 |
+ except IOError as msg:
|
|
| 517 | 517 |
if msg.filename == filename: |
| 518 | 518 |
warn('File not found. Did you forget to save?')
|
| 519 | 519 |
return |
@@ -113,7 +113,7 @@ def pfile(self, parameter_s=''): |
||
| 113 | 113 |
if out == 'not found': |
| 114 | 114 |
try: |
| 115 | 115 |
filename = get_py_filename(parameter_s) |
| 116 |
- except IOError,msg:
|
|
| 116 |
+ except IOError as msg:
|
|
| 117 | 117 |
print msg |
| 118 | 118 |
return |
| 119 | 119 |
page.page(self.shell.inspector.format(open(filename).read())) |
@@ -221,7 +221,7 @@ def page(strng, start=0, screen_lines=0, pager_cmd=None): |
||
| 221 | 221 |
pager.write(strng) |
| 222 | 222 |
pager.close() |
| 223 | 223 |
retval = pager.close() # success returns None |
| 224 |
- except IOError,msg: # broken pipe when user quits
|
|
| 224 |
+ except IOError as msg: # broken pipe when user quits
|
|
| 225 | 225 |
if msg.args == (32,'Broken pipe'): |
| 226 | 226 |
retval = None |
| 227 | 227 |
else: |
@@ -201,7 +201,7 @@ class secondtmp(tt.TempFileMixin): pass |
||
| 201 | 201 |
"for i in range(5):\n" |
| 202 | 202 |
" try:\n" |
| 203 | 203 |
" ip.magic('run %s')\n"
|
| 204 |
- " except NameError, e:\n"
|
|
| 204 |
+ " except NameError as e:\n"
|
|
| 205 | 205 |
" print i;break\n" % empty.fname) |
| 206 | 206 |
self.mktmp(py3compat.doctest_refactor_print(src)) |
| 207 | 207 |
_ip.magic('run %s' % self.fname)
|
@@ -875,7 +875,7 @@ def linereader(file=file, lnum=[lnum], getline=linecache.getline): |
||
| 875 | 875 |
except (IndexError, UnicodeDecodeError): |
| 876 | 876 |
# signals exit of tokenizer |
| 877 | 877 |
pass |
| 878 |
- except tokenize.TokenError,msg:
|
|
| 878 |
+ except tokenize.TokenError as msg:
|
|
| 879 | 879 |
_m = ("An unexpected error occurred while tokenizing input\n"
|
| 880 | 880 |
"The following traceback may be corrupted or invalid\n" |
| 881 | 881 |
"The error message is: %s\n" % msg) |
@@ -217,7 +217,7 @@ def fetch(self, count): |
||
| 217 | 217 |
break |
| 218 | 218 |
except (KeyboardInterrupt, SystemExit): |
| 219 | 219 |
raise |
| 220 |
- except Exception, exc:
|
|
| 220 |
+ except Exception as exc:
|
|
| 221 | 221 |
have += 1 |
| 222 | 222 |
self.items.append(_BrowserCachedItem(exc)) |
| 223 | 223 |
self.exhausted = True |
@@ -260,7 +260,7 @@ def getrow(self, i): |
||
| 260 | 260 |
value = attr.value(item) |
| 261 | 261 |
except (KeyboardInterrupt, SystemExit): |
| 262 | 262 |
raise |
| 263 |
- except Exception, exc:
|
|
| 263 |
+ except Exception as exc:
|
|
| 264 | 264 |
value = exc |
| 265 | 265 |
# only store attribute if it exists (or we got an exception) |
| 266 | 266 |
if value is not ipipe.noitem: |
@@ -652,7 +652,7 @@ def cmd_execute(self, browser): |
||
| 652 | 652 |
break # found something |
| 653 | 653 |
except (KeyboardInterrupt, SystemExit): |
| 654 | 654 |
raise |
| 655 |
- except Exception, exc:
|
|
| 655 |
+ except Exception as exc:
|
|
| 656 | 656 |
browser.report(exc) |
| 657 | 657 |
curses.beep() |
| 658 | 658 |
break # break on error |
@@ -677,7 +677,7 @@ def cmd_execute(self, browser): |
||
| 677 | 677 |
break # found something |
| 678 | 678 |
except (KeyboardInterrupt, SystemExit): |
| 679 | 679 |
raise |
| 680 |
- except Exception, exc:
|
|
| 680 |
+ except Exception as exc:
|
|
| 681 | 681 |
browser.report(exc) |
| 682 | 682 |
curses.beep() |
| 683 | 683 |
break # break on error |
@@ -946,7 +946,7 @@ def enter(self, item, *attrs): |
||
| 946 | 946 |
) |
| 947 | 947 |
except (KeyboardInterrupt, SystemExit): |
| 948 | 948 |
raise |
| 949 |
- except Exception, exc:
|
|
| 949 |
+ except Exception as exc:
|
|
| 950 | 950 |
if not self.levels: |
| 951 | 951 |
raise |
| 952 | 952 |
self._calcheaderlines(oldlevels) |
@@ -1311,7 +1311,7 @@ def cmd_detailattr(self): |
||
| 1311 | 1311 |
item = attr.value(item) |
| 1312 | 1312 |
except (KeyboardInterrupt, SystemExit): |
| 1313 | 1313 |
raise |
| 1314 |
- except Exception, exc:
|
|
| 1314 |
+ except Exception as exc:
|
|
| 1315 | 1315 |
self.report(exc) |
| 1316 | 1316 |
else: |
| 1317 | 1317 |
self.report("entering detail view for attribute %s..." % attr.name())
|
@@ -1638,7 +1638,7 @@ def _dodisplay(self, scr): |
||
| 1638 | 1638 |
value = attr.value(item) |
| 1639 | 1639 |
except (SystemExit, KeyboardInterrupt): |
| 1640 | 1640 |
raise |
| 1641 |
- except Exception, exc:
|
|
| 1641 |
+ except Exception as exc:
|
|
| 1642 | 1642 |
value = exc |
| 1643 | 1643 |
if value is not ipipe.noitem: |
| 1644 | 1644 |
attrstyle = ipipe.xrepr(value, "footer") |
@@ -154,7 +154,7 @@ def _getvalue(self, row, col): |
||
| 154 | 154 |
try: |
| 155 | 155 |
value = self.table._displayattrs[col].value(self.table.items[row]) |
| 156 | 156 |
(align, width, text) = ipipe.xformat(value, "cell", self.maxchars) |
| 157 |
- except Exception, exc:
|
|
| 157 |
+ except Exception as exc:
|
|
| 158 | 158 |
(align, width, text) = ipipe.xformat(exc, "cell", self.maxchars) |
| 159 | 159 |
return (align, text) |
| 160 | 160 |
|
@@ -292,7 +292,7 @@ def _fetch(self, count): |
||
| 292 | 292 |
break |
| 293 | 293 |
except (KeyboardInterrupt, SystemExit): |
| 294 | 294 |
raise |
| 295 |
- except Exception, exc:
|
|
| 295 |
+ except Exception as exc:
|
|
| 296 | 296 |
have += 1 |
| 297 | 297 |
self._append(exc) |
| 298 | 298 |
self.iterator = None |
@@ -413,7 +413,7 @@ def realkey(item): |
||
| 413 | 413 |
return None |
| 414 | 414 |
try: |
| 415 | 415 |
self.table.items = ipipe.deque(sorted(self.table.items, key=realkey, reverse=reverse)) |
| 416 |
- except TypeError, exc:
|
|
| 416 |
+ except TypeError as exc:
|
|
| 417 | 417 |
self.error_output("Exception encountered: %s" % exc)
|
| 418 | 418 |
return |
| 419 | 419 |
# Find out where the object under the cursor went |
@@ -478,7 +478,7 @@ def _getvalue(self, row, col): |
||
| 478 | 478 |
(align, width, text) = ipipe.xformat(value, "cell", self.maxchars) |
| 479 | 479 |
except IndexError: |
| 480 | 480 |
raise IndexError |
| 481 |
- except Exception, exc:
|
|
| 481 |
+ except Exception as exc:
|
|
| 482 | 482 |
(align, width, text) = ipipe.xformat(exc, "cell", self.maxchars) |
| 483 | 483 |
return text |
| 484 | 484 |
|
@@ -505,7 +505,7 @@ def searchexpression(self, searchexp, startrow=None, search_forward=True ): |
||
| 505 | 505 |
break |
| 506 | 506 |
except (KeyboardInterrupt, SystemExit): |
| 507 | 507 |
raise |
| 508 |
- except Exception, exc:
|
|
| 508 |
+ except Exception as exc:
|
|
| 509 | 509 |
frame.SetStatusText(str(exc)) |
| 510 | 510 |
wx.Bell() |
| 511 | 511 |
break # break on error |
@@ -529,7 +529,7 @@ def searchexpression(self, searchexp, startrow=None, search_forward=True ): |
||
| 529 | 529 |
break |
| 530 | 530 |
except (KeyboardInterrupt, SystemExit): |
| 531 | 531 |
raise |
| 532 |
- except Exception, exc:
|
|
| 532 |
+ except Exception as exc:
|
|
| 533 | 533 |
frame.SetStatusText(str(exc)) |
| 534 | 534 |
wx.Bell() |
| 535 | 535 |
break # break on error |
@@ -739,7 +739,7 @@ def _doenter(self, value, *attrs): |
||
| 739 | 739 |
for i in xrange(count-1, current, -1): # some tabs don't close if we don't close in *reverse* order |
| 740 | 740 |
nb.DeletePage(i) |
| 741 | 741 |
frame._add_notebook(value) |
| 742 |
- except TypeError, exc:
|
|
| 742 |
+ except TypeError as exc:
|
|
| 743 | 743 |
if exc.__class__.__module__ == "exceptions": |
| 744 | 744 |
msg = "%s: %s" % (exc.__class__.__name__, exc) |
| 745 | 745 |
else: |
@@ -750,7 +750,7 @@ def enterattr(self, row, col): |
||
| 750 | 750 |
try: |
| 751 | 751 |
attr = self.table._displayattrs[col] |
| 752 | 752 |
value = attr.value(self.table.items[row]) |
| 753 |
- except Exception, exc:
|
|
| 753 |
+ except Exception as exc:
|
|
| 754 | 754 |
self.error_output(str(exc)) |
| 755 | 755 |
else: |
| 756 | 756 |
self._doenter(value) |
@@ -762,7 +762,7 @@ def set_footer(self, item): |
||
| 762 | 762 |
def enter(self, row): |
| 763 | 763 |
try: |
| 764 | 764 |
value = self.table.items[row] |
| 765 |
- except Exception, exc:
|
|
| 765 |
+ except Exception as exc:
|
|
| 766 | 766 |
self.error_output(str(exc)) |
| 767 | 767 |
else: |
| 768 | 768 |
self._doenter(value) |
@@ -774,7 +774,7 @@ def detail(self, row, col): |
||
| 774 | 774 |
try: |
| 775 | 775 |
attr = self.table._displayattrs[col] |
| 776 | 776 |
item = self.table.items[row] |
| 777 |
- except Exception, exc:
|
|
| 777 |
+ except Exception as exc:
|
|
| 778 | 778 |
self.error_output(str(exc)) |
| 779 | 779 |
else: |
| 780 | 780 |
attrs = [ipipe.AttributeDetail(item, attr) for attr in ipipe.xattrs(item, "detail")] |
@@ -784,7 +784,7 @@ def detail_attr(self, row, col): |
||
| 784 | 784 |
try: |
| 785 | 785 |
attr = self.table._displayattrs[col] |
| 786 | 786 |
item = attr.value(self.table.items[row]) |
| 787 |
- except Exception, exc:
|
|
| 787 |
+ except Exception as exc:
|
|
| 788 | 788 |
self.error_output(str(exc)) |
| 789 | 789 |
else: |
| 790 | 790 |
attrs = [ipipe.AttributeDetail(item, attr) for attr in ipipe.xattrs(item, "detail")] |
@@ -819,7 +819,7 @@ def pick(self, row): |
||
| 819 | 819 |
""" |
| 820 | 820 |
try: |
| 821 | 821 |
value = self.table.items[row] |
| 822 |
- except Exception, exc:
|
|
| 822 |
+ except Exception as exc:
|
|
| 823 | 823 |
self.error_output(str(exc)) |
| 824 | 824 |
else: |
| 825 | 825 |
self.quit(value) |
@@ -827,7 +827,7 @@ def pick(self, row): |
||
| 827 | 827 |
def pickinput(self, row): |
| 828 | 828 |
try: |
| 829 | 829 |
value = self.table.items[row] |
| 830 |
- except Exception, exc:
|
|
| 830 |
+ except Exception as exc:
|
|
| 831 | 831 |
self.error_output(str(exc)) |
| 832 | 832 |
else: |
| 833 | 833 |
api = ipapi.get() |
@@ -838,7 +838,7 @@ def pickinputattr(self, row, col): |
||
| 838 | 838 |
try: |
| 839 | 839 |
attr = self.table._displayattrs[col] |
| 840 | 840 |
value = attr.value(self.table.items[row]) |
| 841 |
- except Exception, exc:
|
|
| 841 |
+ except Exception as exc:
|
|
| 842 | 842 |
self.error_output(str(exc)) |
| 843 | 843 |
else: |
| 844 | 844 |
api = ipapi.get() |
@@ -851,7 +851,7 @@ def pickrows(self, rows): |
||
| 851 | 851 |
""" |
| 852 | 852 |
try: |
| 853 | 853 |
value = [self.table.items[row] for row in rows] |
| 854 |
- except Exception, exc:
|
|
| 854 |
+ except Exception as exc:
|
|
| 855 | 855 |
self.error_output(str(exc)) |
| 856 | 856 |
else: |
| 857 | 857 |
self.quit(value) |
@@ -870,7 +870,7 @@ def pickrowsattr(self, rows, col): |
||
| 870 | 870 |
raise |
| 871 | 871 |
except Exception: |
| 872 | 872 |
raise #pass |
| 873 |
- except Exception, exc:
|
|
| 873 |
+ except Exception as exc:
|
|
| 874 | 874 |
self.error_output(str(exc)) |
| 875 | 875 |
else: |
| 876 | 876 |
self.quit(values) |
@@ -879,7 +879,7 @@ def pickattr(self, row, col): |
||
| 879 | 879 |
try: |
| 880 | 880 |
attr = self.table._displayattrs[col] |
| 881 | 881 |
value = attr.value(self.table.items[row]) |
| 882 |
- except Exception, exc:
|
|
| 882 |
+ except Exception as exc:
|
|
| 883 | 883 |
self.error_output(str(exc)) |
| 884 | 884 |
else: |
| 885 | 885 |
self.quit(value) |
@@ -959,7 +959,7 @@ def refresh_interval(self, event): |
||
| 959 | 959 |
if dlg.ShowModal() == wx.ID_OK: |
| 960 | 960 |
try: |
| 961 | 961 |
milliseconds = int(dlg.GetValue()) |
| 962 |
- except ValueError, exc:
|
|
| 962 |
+ except ValueError as exc:
|
|
| 963 | 963 |
self.SetStatusText(str(exc)) |
| 964 | 964 |
else: |
| 965 | 965 |
table.timer.Start(milliseconds=milliseconds, oneShot=False) |
@@ -1796,7 +1796,7 @@ def test(item): |
||
| 1796 | 1796 |
ok += 1 |
| 1797 | 1797 |
except (KeyboardInterrupt, SystemExit): |
| 1798 | 1798 |
raise |
| 1799 |
- except Exception, exc:
|
|
| 1799 |
+ except Exception as exc:
|
|
| 1800 | 1800 |
if self.errors == "drop": |
| 1801 | 1801 |
pass # Ignore errors |
| 1802 | 1802 |
elif self.errors == "keep": |
@@ -1869,7 +1869,7 @@ def do(item): |
||
| 1869 | 1869 |
yield do(item) |
| 1870 | 1870 |
except (KeyboardInterrupt, SystemExit): |
| 1871 | 1871 |
raise |
| 1872 |
- except Exception, exc:
|
|
| 1872 |
+ except Exception as exc:
|
|
| 1873 | 1873 |
if self.errors == "drop": |
| 1874 | 1874 |
pass # Ignore errors |
| 1875 | 1875 |
elif self.errors == "keep": |
@@ -2040,7 +2040,7 @@ def display(self): |
||
| 2040 | 2040 |
pager.write("\n")
|
| 2041 | 2041 |
finally: |
| 2042 | 2042 |
pager.close() |
| 2043 |
- except Exception, exc:
|
|
| 2043 |
+ except Exception as exc:
|
|
| 2044 | 2044 |
print "%s: %s" % (exc.__class__.__name__, str(exc)) |
| 2045 | 2045 |
|
| 2046 | 2046 |
|
@@ -2187,7 +2187,7 @@ def display(self): |
||
| 2187 | 2187 |
value = attr.value(item) |
| 2188 | 2188 |
except (KeyboardInterrupt, SystemExit): |
| 2189 | 2189 |
raise |
| 2190 |
- except Exception, exc:
|
|
| 2190 |
+ except Exception as exc:
|
|
| 2191 | 2191 |
value = exc |
| 2192 | 2192 |
(align, width, text) = xformat(value, "cell", self.maxattrlength) |
| 2193 | 2193 |
colwidths[attr] = max(colwidths[attr], width) |
@@ -246,7 +246,7 @@ def execute(self, block, blockID=None): |
||
| 246 | 246 |
|
| 247 | 247 |
try: |
| 248 | 248 |
result = self.shell.execute(block) |
| 249 |
- except Exception,e:
|
|
| 249 |
+ except Exception as e:
|
|
| 250 | 250 |
e = self._add_block_id_for_failure(e, blockID=blockID) |
| 251 | 251 |
e = self.update_cell_prompt(e, blockID=blockID) |
| 252 | 252 |
e = self.render_error(e) |
@@ -161,7 +161,7 @@ def is_complete(self, string): |
||
| 161 | 161 |
is_complete = codeop.compile_command(clean_string, |
| 162 | 162 |
"<string>", "exec") |
| 163 | 163 |
self.release_output() |
| 164 |
- except Exception, e:
|
|
| 164 |
+ except Exception as e:
|
|
| 165 | 165 |
# XXX: Hack: return True so that the |
| 166 | 166 |
# code gets executed and the error captured. |
| 167 | 167 |
is_complete = True |
@@ -5,7 +5,7 @@ |
||
| 5 | 5 |
|
| 6 | 6 |
try: |
| 7 | 7 |
import wx |
| 8 |
-except ImportError, e:
|
|
| 8 |
+except ImportError as e:
|
|
| 9 | 9 |
e.args[0] = """%s |
| 10 | 10 |
________________________________________________________________________________ |
| 11 | 11 |
You need wxPython to run this application. |
@@ -8,7 +8,7 @@ |
||
| 8 | 8 |
import numpy.testing as npt |
| 9 | 9 |
|
| 10 | 10 |
from IPython.extensions import octavemagic |
| 11 |
-except Exception, e:
|
|
| 11 |
+except Exception as e:
|
|
| 12 | 12 |
__test__ = False |
| 13 | 13 |
|
| 14 | 14 |
global octave |
@@ -79,7 +79,7 @@ |
||
| 79 | 79 |
import errno |
| 80 | 80 |
import traceback |
| 81 | 81 |
import signal |
| 82 |
-except ImportError, e:
|
|
| 82 |
+except ImportError as e:
|
|
| 83 | 83 |
raise ImportError (str(e) + """ |
| 84 | 84 |
|
| 85 | 85 |
A critical module was not found. Probably this operating system does not |
@@ -265,10 +265,10 @@ def print_ticks(d): |
||
| 265 | 265 |
else: |
| 266 | 266 |
raise TypeError ('The callback must be a string or function type.')
|
| 267 | 267 |
event_count = event_count + 1 |
| 268 |
- except TIMEOUT, e:
|
|
| 268 |
+ except TIMEOUT as e:
|
|
| 269 | 269 |
child_result_list.append(child.before) |
| 270 | 270 |
break |
| 271 |
- except EOF, e:
|
|
| 271 |
+ except EOF as e:
|
|
| 272 | 272 |
child_result_list.append(child.before) |
| 273 | 273 |
break |
| 274 | 274 |
child_result = child._empty_buffer.join(child_result_list) |
@@ -552,7 +552,7 @@ def _spawn(self,command,args=[]): |
||
| 552 | 552 |
if self.use_native_pty_fork: |
| 553 | 553 |
try: |
| 554 | 554 |
self.pid, self.child_fd = pty.fork() |
| 555 |
- except OSError, e:
|
|
| 555 |
+ except OSError as e:
|
|
| 556 | 556 |
raise ExceptionPexpect('Error! pty.fork() failed: ' + str(e))
|
| 557 | 557 |
else: # Use internal __fork_pty |
| 558 | 558 |
self.pid, self.child_fd = self.__fork_pty() |
@@ -857,7 +857,7 @@ def read_nonblocking (self, size = 1, timeout = -1): |
||
| 857 | 857 |
if self.child_fd in r: |
| 858 | 858 |
try: |
| 859 | 859 |
s = os.read(self.child_fd, size) |
| 860 |
- except OSError, e: # Linux does this
|
|
| 860 |
+ except OSError as e: # Linux does this
|
|
| 861 | 861 |
self.flag_eof = True |
| 862 | 862 |
raise EOF ('End Of File (EOF) in read_nonblocking(). Exception style platform.')
|
| 863 | 863 |
if s == b'': # BSD style |
@@ -1106,7 +1106,7 @@ def terminate(self, force=False): |
||
| 1106 | 1106 |
else: |
| 1107 | 1107 |
return False |
| 1108 | 1108 |
return False |
| 1109 |
- except OSError, e:
|
|
| 1109 |
+ except OSError as e:
|
|
| 1110 | 1110 |
# I think there are kernel timing issues that sometimes cause |
| 1111 | 1111 |
# this to happen. I think isalive() reports True, but the |
| 1112 | 1112 |
# process is dead to the kernel. |
@@ -1177,7 +1177,7 @@ def isalive(self): |
||
| 1177 | 1177 |
if pid == 0: |
| 1178 | 1178 |
try: |
| 1179 | 1179 |
pid, status = os.waitpid(self.pid, waitpid_options) ### os.WNOHANG) # Solaris! |
| 1180 |
- except OSError, e: # This should never happen...
|
|
| 1180 |
+ except OSError as e: # This should never happen...
|
|
| 1181 | 1181 |
if e[0] == errno.ECHILD: |
| 1182 | 1182 |
raise ExceptionPexpect ('isalive() encountered condition that should never happen. There was no child process. Did someone else call waitpid() on our process?')
|
| 1183 | 1183 |
else: |
@@ -1424,7 +1424,7 @@ def expect_loop(self, searcher, timeout = -1, searchwindowsize = -1): |
||
| 1424 | 1424 |
incoming = incoming + c |
| 1425 | 1425 |
if timeout is not None: |
| 1426 | 1426 |
timeout = end_time - time.time() |
| 1427 |
- except EOF, e:
|
|
| 1427 |
+ except EOF as e:
|
|
| 1428 | 1428 |
self.buffer = self._empty_buffer |
| 1429 | 1429 |
self.before = incoming |
| 1430 | 1430 |
self.after = EOF |
@@ -1437,7 +1437,7 @@ def expect_loop(self, searcher, timeout = -1, searchwindowsize = -1): |
||
| 1437 | 1437 |
self.match = None |
| 1438 | 1438 |
self.match_index = None |
| 1439 | 1439 |
raise EOF (str(e) + '\n' + str(self)) |
| 1440 |
- except TIMEOUT, e:
|
|
| 1440 |
+ except TIMEOUT as e:
|
|
| 1441 | 1441 |
self.buffer = incoming |
| 1442 | 1442 |
self.before = incoming |
| 1443 | 1443 |
self.after = TIMEOUT |
@@ -45,7 +45,7 @@ def handle(self): |
||
| 45 | 45 |
chan = self.ssh_transport.open_channel('direct-tcpip',
|
| 46 | 46 |
(self.chain_host, self.chain_port), |
| 47 | 47 |
self.request.getpeername()) |
| 48 |
- except Exception, e:
|
|
| 48 |
+ except Exception as e:
|
|
| 49 | 49 |
logger.debug('Incoming request to %s:%d failed: %s' % (self.chain_host,
|
| 50 | 50 |
self.chain_port, |
| 51 | 51 |
repr(e))) |
@@ -447,7 +447,7 @@ def init_webapp(self): |
||
| 447 | 447 |
for port in random_ports(self.port, self.port_retries+1): |
| 448 | 448 |
try: |
| 449 | 449 |
self.http_server.listen(port, self.ip) |
| 450 |
- except socket.error, e:
|
|
| 450 |
+ except socket.error as e:
|
|
| 451 | 451 |
if e.errno != errno.EADDRINUSE: |
| 452 | 452 |
raise |
| 453 | 453 |
self.log.info('The port %i is already in use, trying another random port.' % port)
|
@@ -111,7 +111,7 @@ def export(self): |
||
| 111 | 111 |
# Perform the export! |
| 112 | 112 |
try: |
| 113 | 113 |
return exporter(html, self.filename, self.image_tag) |
| 114 |
- except Exception, e:
|
|
| 114 |
+ except Exception as e:
|
|
| 115 | 115 |
msg = "Error exporting HTML to %s\n" % self.filename + str(e) |
| 116 | 116 |
reply = QtGui.QMessageBox.warning(parent, 'Error', msg, |
| 117 | 117 |
QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ok) |
@@ -551,7 +551,7 @@ def inner(obj, p, cycle): |
||
| 551 | 551 |
keys = obj.keys() |
| 552 | 552 |
try: |
| 553 | 553 |
keys.sort() |
| 554 |
- except Exception, e:
|
|
| 554 |
+ except Exception as e:
|
|
| 555 | 555 |
# Sometimes the keys don't sort. |
| 556 | 556 |
pass |
| 557 | 557 |
for idx, key in enumerate(keys): |
@@ -151,7 +151,7 @@ def wait(self, timeout=-1): |
||
| 151 | 151 |
else: |
| 152 | 152 |
results = error.collect_exceptions(results, self._fname) |
| 153 | 153 |
self._result = self._reconstruct_result(results) |
| 154 |
- except Exception, e:
|
|
| 154 |
+ except Exception as e:
|
|
| 155 | 155 |
self._exception = e |
| 156 | 156 |
self._success = False |
| 157 | 157 |
else: |
@@ -675,7 +675,7 @@ def wait(self, timeout=-1): |
||
| 675 | 675 |
else: |
| 676 | 676 |
results = error.collect_exceptions(results, self._fname) |
| 677 | 677 |
self._result = self._reconstruct_result(results) |
| 678 |
- except Exception, e:
|
|
| 678 |
+ except Exception as e:
|
|
| 679 | 679 |
self._exception = e |
| 680 | 680 |
self._success = False |
| 681 | 681 |
else: |
@@ -683,4 +683,4 @@ def wait(self, timeout=-1): |
||
| 683 | 683 |
finally: |
| 684 | 684 |
self._metadata = map(self._client.metadata.get, self.msg_ids) |
| 685 | 685 |
|
| 686 |
-__all__ = ['AsyncResult', 'AsyncMapResult', 'AsyncHubResult']
|
|
| 686 |
+__all__ = ['AsyncResult', 'AsyncMapResult', 'AsyncHubResult'] |
|
@@ -107,7 +107,7 @@ def teardown(): |
||
| 107 | 107 |
if p.poll() is None: |
| 108 | 108 |
try: |
| 109 | 109 |
p.stop() |
| 110 |
- except Exception, e:
|
|
| 110 |
+ except Exception as e:
|
|
| 111 | 111 |
print e |
| 112 | 112 |
pass |
| 113 | 113 |
if p.poll() is None: |
@@ -78,7 +78,7 @@ def line_edit_f(self, cmd ): |
||
| 78 | 78 |
for l in curdata: |
| 79 | 79 |
try: |
| 80 | 80 |
l2 = eval(cmd) |
| 81 |
- except Exception,e:
|
|
| 81 |
+ except Exception as e:
|
|
| 82 | 82 |
print "Dropping exception",e,"on line:",l |
| 83 | 83 |
continue |
| 84 | 84 |
newlines.append(l2) |
@@ -95,4 +95,4 @@ def line_edit_complete_f(self,event): |
||
| 95 | 95 |
|
| 96 | 96 |
ip.set_hook('complete_command', line_edit_complete_f , str_key = '%led')
|
| 97 | 97 |
|
| 98 |
-ip.define_magic('led', line_edit_f)
|
|
| 98 |
+ip.define_magic('led', line_edit_f)
|
|
@@ -308,7 +308,7 @@ def tearDown(self): |
||
| 308 | 308 |
# and letting any other error propagate. |
| 309 | 309 |
try: |
| 310 | 310 |
super(DocTestCase, self).tearDown() |
| 311 |
- except AttributeError, exc:
|
|
| 311 |
+ except AttributeError as exc:
|
|
| 312 | 312 |
if exc.args[0] != self._result_var: |
| 313 | 313 |
raise |
| 314 | 314 |
|
@@ -282,7 +282,7 @@ def main(argv=None): |
||
| 282 | 282 |
else: |
| 283 | 283 |
try: |
| 284 | 284 |
stream = open(fname) |
| 285 |
- except IOError,msg:
|
|
| 285 |
+ except IOError as msg:
|
|
| 286 | 286 |
print >> sys.stderr, msg |
| 287 | 287 |
sys.exit(1) |
| 288 | 288 |
|
@@ -294,7 +294,7 @@ def main(argv=None): |
||
| 294 | 294 |
try: |
| 295 | 295 |
# write colorized version to stdout |
| 296 | 296 |
parser.format(stream.read(),scheme=opts.scheme_name) |
| 297 |
- except IOError,msg:
|
|
| 297 |
+ except IOError as msg:
|
|
| 298 | 298 |
# if user reads through a pager and quits, don't print traceback |
| 299 | 299 |
if msg.args != (32,'Broken pipe'): |
| 300 | 300 |
raise |
@@ -34,7 +34,7 @@ def read_no_interrupt(p): |
||
| 34 | 34 |
|
| 35 | 35 |
try: |
| 36 | 36 |
return p.read() |
| 37 |
- except IOError, err:
|
|
| 37 |
+ except IOError as err:
|
|
| 38 | 38 |
if err.errno != errno.EINTR: |
| 39 | 39 |
raise |
| 40 | 40 |
|
@@ -19,7 +19,7 @@ def daemonize(): |
||
| 19 | 19 |
for i in range(3): |
| 20 | 20 |
try: |
| 21 | 21 |
os.dup2(null, i) |
| 22 |
- except OSError, e:
|
|
| 22 |
+ except OSError as e:
|
|
| 23 | 23 |
if e.errno != errno.EBADF: |
| 24 | 24 |
raise |
| 25 | 25 |
os.close(null) |
@@ -121,7 +121,7 @@ def __setattr__(self, key, value): |
||
| 121 | 121 |
) |
| 122 | 122 |
try: |
| 123 | 123 |
self.__setitem__(key, value) |
| 124 |
- except KeyError, e:
|
|
| 124 |
+ except KeyError as e:
|
|
| 125 | 125 |
raise AttributeError(e) |
| 126 | 126 |
|
| 127 | 127 |
def __getattr__(self, key): |
@@ -85,7 +85,7 @@ def __setitem__(self,key,value): |
||
| 85 | 85 |
pickled = pickle.dump(value,fil.open('wb'), protocol=2)
|
| 86 | 86 |
try: |
| 87 | 87 |
self.cache[fil] = (value,fil.mtime) |
| 88 |
- except OSError,e:
|
|
| 88 |
+ except OSError as e:
|
|
| 89 | 89 |
if e.errno != 2: |
| 90 | 90 |
raise |
| 91 | 91 |
|
@@ -897,7 +897,7 @@ def kill_kernel(self): |
||
| 897 | 897 |
# Attempt to kill the kernel. |
| 898 | 898 |
try: |
| 899 | 899 |
self.kernel.kill() |
| 900 |
- except OSError, e:
|
|
| 900 |
+ except OSError as e:
|
|
| 901 | 901 |
# In Windows, we will get an Access Denied error if the process |
| 902 | 902 |
# has already terminated. Ignore it. |
| 903 | 903 |
if sys.platform == 'win32': |
@@ -29,7 +29,7 @@ def run(self): |
||
| 29 | 29 |
if os.getppid() == 1: |
| 30 | 30 |
os._exit(1) |
| 31 | 31 |
time.sleep(1.0) |
| 32 |
- except OSError, e:
|
|
| 32 |
+ except OSError as e:
|
|
| 33 | 33 |
if e.errno == EINTR: |
| 34 | 34 |
continue |
| 35 | 35 |
raise |
@@ -413,7 +413,7 @@ def __init__(self, func, role='func', doc=None): |
||
| 413 | 413 |
doc = inspect.getdoc(func) or '' |
| 414 | 414 |
try: |
| 415 | 415 |
NumpyDocString.__init__(self, doc) |
| 416 |
- except ValueError, e:
|
|
| 416 |
+ except ValueError as e:
|
|
| 417 | 417 |
print '*'*78 |
| 418 | 418 |
print "ERROR: '%s' while parsing `%s`" % (e, self._f) |
| 419 | 419 |
print '*'*78 |
@@ -429,7 +429,7 @@ def __init__(self, func, role='func', doc=None): |
||
| 429 | 429 |
argspec = inspect.formatargspec(*argspec) |
| 430 | 430 |
argspec = argspec.replace('*','\*')
|
| 431 | 431 |
signature = '%s%s' % (func_name, argspec) |
| 432 |
- except TypeError, e:
|
|
| 432 |
+ except TypeError as e:
|
|
| 433 | 433 |
signature = '%s()' % func_name |
| 434 | 434 |
self['Signature'] = signature |
| 435 | 435 |
|
@@ -36,7 +36,7 @@ def make_link_node(rawtext, app, type, slug, options): |
||
| 36 | 36 |
raise AttributeError |
| 37 | 37 |
if not base.endswith('/'):
|
| 38 | 38 |
base += '/' |
| 39 |
- except AttributeError, err:
|
|
| 39 |
+ except AttributeError as err:
|
|
| 40 | 40 |
raise ValueError('github_project_url configuration value is not set (%s)' % str(err))
|
| 41 | 41 |
|
| 42 | 42 |
ref = base + type + '/' + slug + '/' |
@@ -133,7 +133,7 @@ def ghcommit_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
|
||
| 133 | 133 |
raise AttributeError |
| 134 | 134 |
if not base.endswith('/'):
|
| 135 | 135 |
base += '/' |
| 136 |
- except AttributeError, err:
|
|
| 136 |
+ except AttributeError as err:
|
|
| 137 | 137 |
raise ValueError('github_project_url configuration value is not set (%s)' % str(err))
|
| 138 | 138 |
|
| 139 | 139 |
ref = base + text |
@@ -380,7 +380,7 @@ def visit_inheritance_diagram(inner_func): |
||
| 380 | 380 |
def visitor(self, node): |
| 381 | 381 |
try: |
| 382 | 382 |
content = inner_func(self, node) |
| 383 |
- except DotException, e:
|
|
| 383 |
+ except DotException as e:
|
|
| 384 | 384 |
# Insert the exception as a warning in the document |
| 385 | 385 |
warning = self.document.reporter.warning(str(e), line=node.line) |
| 386 | 386 |
warning.parent = node |
@@ -234,6 +234,12 @@ def cleanup(): |
||
| 234 | 234 |
|
| 235 | 235 |
if PY3: |
| 236 | 236 |
setuptools_extra_args['use_2to3'] = True |
| 237 |
+ # we try to make a 2.6, 2.7, and 3.1 to 3.3 python compatible code |
|
| 238 |
+ # so we explicitly disable some 2to3 fixes to be sure we aren't forgetting |
|
| 239 |
+ # anything. |
|
| 240 |
+ setuptools_extra_args['use_2to3_exclude_fixers'] = [ |
|
| 241 |
+ 'lib2to3.fixes.fix_except', |
|
| 242 |
+ ] |
|
| 237 | 243 |
from setuptools.command.build_py import build_py |
| 238 | 244 |
setup_args['cmdclass'] = {'build_py': record_commit_info('IPython', build_cmd=build_py)}
|
| 239 | 245 |
setuptools_extra_args['entry_points'] = find_scripts(True, suffix='3') |
Tip: You can add notes to lines in a file. Hover to the left of a line to make a note
brutally replace all
exeption <type>, <name>:byexception <type> as <name> :exception <type>, <type> :should not be present anywhere in the codeanymore, or should be present with explicit tuple as
exception (<type>, <type>) :see also #2061