Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 572d3d7

Browse files
committed
Merge branch 'takowl-ipy3-preparation' into trunk
This branch cleans up our trunk to make a 2to3 run be as painless as possible, while keeping our code fully 2.6-compatible. Closes gh-159 (pull request).
2 parents 263d8f1 + 468a14f commit 572d3d7

22 files changed

Lines changed: 82 additions & 160 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ docs/source/api/generated
44
*.pyc
55
build
66
*.egg-info
7+
*.py~
8+
*.bak

IPython/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
# Release data
4949
__author__ = ''
50-
for author, email in release.authors.values():
50+
for author, email in release.authors.itervalues():
5151
__author__ += author + ' <' + email + '>\n'
5252
__license__ = release.license
5353
__version__ = release.version

IPython/config/configurable.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _config_changed(self, name, old, new):
112112
# dynamically create the section with name self.__class__.__name__.
113113
if new._has_section(sname):
114114
my_config = new[sname]
115-
for k, v in traits.items():
115+
for k, v in traits.iteritems():
116116
# Don't allow traitlets with config=True to start with
117117
# uppercase. Otherwise, they are confused with Config
118118
# subsections. But, developers shouldn't have uppercase

IPython/config/loader.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
# coding: utf-8
23
"""A simple configuration system.
34
@@ -73,7 +74,7 @@ def __init__(self, *args, **kwds):
7374

7475
def _merge(self, other):
7576
to_update = {}
76-
for k, v in other.items():
77+
for k, v in other.iteritems():
7778
if not self.has_key(k):
7879
to_update[k] = v
7980
else: # I have this key
@@ -92,15 +93,17 @@ def _is_section_key(self, key):
9293
else:
9394
return False
9495

95-
def has_key(self, key):
96+
def __contains__(self, key):
9697
if self._is_section_key(key):
9798
return True
9899
else:
99-
return dict.has_key(self, key)
100+
return super(Config, self).__contains__(key)
101+
# .has_key is deprecated for dictionaries.
102+
has_key = __contains__
100103

101104
def _has_section(self, key):
102105
if self._is_section_key(key):
103-
if dict.has_key(self, key):
106+
if super(Config, self).__contains__(key):
104107
return True
105108
return False
106109

@@ -363,7 +366,7 @@ def _parse_args(self, args):
363366

364367
def _convert_to_config(self):
365368
"""self.parsed_data->self.config"""
366-
for k, v in vars(self.parsed_data).items():
369+
for k, v in vars(self.parsed_data).iteritems():
367370
exec_str = 'self.config.' + k + '= v'
368371
exec exec_str in locals(), globals()
369372

IPython/core/completerlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def cd_completer(self, event):
336336
return [compress_user(relpath, tilde_expand, tilde_val)]
337337

338338
# if no completions so far, try bookmarks
339-
bks = self.db.get('bookmarks',{}).keys()
339+
bks = self.db.get('bookmarks',{}).iterkeys()
340340
bkmatches = [s for s in bks if s.startswith(event.symbol)]
341341
if bkmatches:
342342
return bkmatches

IPython/core/history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def add(self, ent):
260260

261261
def all(self):
262262
d = self.db.hdict('shadowhist')
263-
items = [(i,s) for (s,i) in d.items()]
263+
items = [(i,s) for (s,i) in d.iteritems()]
264264
items.sort()
265265
return items
266266

IPython/core/interactiveshell.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
import abc
2323
import atexit
2424
import codeop
25-
import exceptions
26-
import new
2725
import os
2826
import re
2927
import string
3028
import sys
3129
import tempfile
30+
import types
3231
from contextlib import nested
3332

3433
from IPython.config.configurable import Configurable
@@ -102,7 +101,7 @@ def softspace(file, newvalue):
102101

103102
def no_op(*a, **kw): pass
104103

105-
class SpaceInInput(exceptions.Exception): pass
104+
class SpaceInInput(Exception): pass
106105

107106
class Bunch: pass
108107

@@ -512,7 +511,7 @@ def save_sys_module_state(self):
512511
def restore_sys_module_state(self):
513512
"""Restore the state of the sys module."""
514513
try:
515-
for k, v in self._orig_sys_module_state.items():
514+
for k, v in self._orig_sys_module_state.iteritems():
516515
setattr(sys, k, v)
517516
except AttributeError:
518517
pass
@@ -550,7 +549,7 @@ def set_hook(self,name,hook, priority = 50, str_key = None, re_key = None):
550549
# accepts it. Probably at least check that the hook takes the number
551550
# of args it's supposed to.
552551

553-
f = new.instancemethod(hook,self,self.__class__)
552+
f = types.MethodType(hook, self)
554553

555554
# check if the hook is for strdispatcher first
556555
if str_key is not None:
@@ -1249,7 +1248,7 @@ def init_history(self):
12491248
def init_shadow_hist(self):
12501249
try:
12511250
self.db = pickleshare.PickleShareDB(self.ipython_dir + "/db")
1252-
except exceptions.UnicodeDecodeError:
1251+
except UnicodeDecodeError:
12531252
print "Your ipython_dir can't be decoded to unicode!"
12541253
print "Please set HOME environment variable to something that"
12551254
print r"only has ASCII characters, e.g. c:\home"
@@ -1414,7 +1413,7 @@ def dummy_handler(self,etype,value,tb):
14141413

14151414
if handler is None: handler = dummy_handler
14161415

1417-
self.CustomTB = new.instancemethod(handler,self,self.__class__)
1416+
self.CustomTB = types.MethodType(handler, self)
14181417
self.custom_exceptions = exc_tuple
14191418

14201419
def excepthook(self, etype, value, tb):
@@ -1756,8 +1755,7 @@ def set_custom_completer(self, completer, pos=0):
17561755
The position argument (defaults to 0) is the index in the completers
17571756
list where you want the completer to be inserted."""
17581757

1759-
newcomp = new.instancemethod(completer,self.Completer,
1760-
self.Completer.__class__)
1758+
newcomp = types.MethodType(completer, self.Completer)
17611759
self.Completer.matchers.insert(pos,newcomp)
17621760

17631761
def set_readline_completer(self):
@@ -1828,12 +1826,11 @@ def foo_impl(self,parameter_s=''):
18281826
print 'Magic function. Passed parameter is between < >:'
18291827
print '<%s>' % parameter_s
18301828
print 'The self object is:',self
1831-
1829+
newcomp = types.MethodType(completer, self.Completer)
18321830
self.define_magic('foo',foo_impl)
18331831
"""
18341832

1835-
import new
1836-
im = new.instancemethod(func,self, self.__class__)
1833+
im = types.MethodType(func, self)
18371834
old = getattr(self, "magic_" + magicname, None)
18381835
setattr(self, "magic_" + magicname, im)
18391836
return old

IPython/core/prefilter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def sort_transformers(self):
237237
This must be called after the priority of a transformer is changed.
238238
The :meth:`register_transformer` method calls this automatically.
239239
"""
240-
self._transformers.sort(cmp=lambda x,y: x.priority-y.priority)
240+
self._transformers.sort(key=lambda x: x.priority)
241241

242242
@property
243243
def transformers(self):
@@ -273,7 +273,7 @@ def sort_checkers(self):
273273
This must be called after the priority of a checker is changed.
274274
The :meth:`register_checker` method calls this automatically.
275275
"""
276-
self._checkers.sort(cmp=lambda x,y: x.priority-y.priority)
276+
self._checkers.sort(key=lambda x: x.priority)
277277

278278
@property
279279
def checkers(self):

IPython/core/tests/test_inputsplitter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# Note: at the bottom, there's a slightly more complete version of this that
2929
# can be useful during development of code here.
3030

31-
def mini_interactive_loop(raw_input):
31+
def mini_interactive_loop(input_func):
3232
"""Minimal example of the logic of an interactive interpreter loop.
3333
3434
This serves as an example, and it is used by the test system with a fake
@@ -43,7 +43,7 @@ def mini_interactive_loop(raw_input):
4343
while isp.push_accepts_more():
4444
indent = ' '*isp.indent_spaces
4545
prompt = '>>> ' + indent
46-
line = indent + raw_input(prompt)
46+
line = indent + input_func(prompt)
4747
isp.push(line)
4848

4949
# Here we just return input so we can use it in a test suite, but a real
@@ -356,7 +356,7 @@ def check_ns(self, lines, ns):
356356
# We can't check that the provided ns is identical to the test_ns,
357357
# because Python fills test_ns with extra keys (copyright, etc). But
358358
# we can check that the given dict is *contained* in test_ns
359-
for k,v in ns.items():
359+
for k,v in ns.iteritems():
360360
self.assertEqual(test_ns[k], v)
361361

362362
def test_simple(self):

IPython/core/tests/test_magic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_rehashx():
3333
# Practically ALL ipython development systems will have more than 10 aliases
3434

3535
yield (nt.assert_true, len(_ip.alias_manager.alias_table) > 10)
36-
for key, val in _ip.alias_manager.alias_table.items():
36+
for key, val in _ip.alias_manager.alias_table.iteritems():
3737
# we must strip dots from alias names
3838
nt.assert_true('.' not in key)
3939

0 commit comments

Comments
 (0)