Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion IPython/config/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, *args, **kwds):
def _merge(self, other):
to_update = {}
for k, v in other.iteritems():
if not self.has_key(k):
if k not in self:
to_update[k] = v
else: # I have this key
if isinstance(v, Config):
Expand Down
4 changes: 2 additions & 2 deletions IPython/config/tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,11 @@ def test_setget(self):
c = Config()
c.a = 10
self.assertEquals(c.a, 10)
self.assertEquals(c.has_key('b'), False)
self.assertEquals('b' in c, False)

def test_auto_section(self):
c = Config()
self.assertEquals(c.has_key('A'), True)
self.assertEquals('A' in c, True)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we patch 2.6 to allow assertIn here, do you want to make that change while you are at it?

Also, just noting that this will conflict with your own #2089, so it will need a tiny rebase after that goes in.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In IPython.testing.nose_assert_methods, we only add nt.assert_in and nt.assert_not_in.

I don't believe that we monkey patch unittest.TestCase to add assertIn, etc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, never mind then.

self.assertEquals(c._has_section('A'), False)
A = c.A
A.foo = 'hi there'
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def define_alias(self, name, cmd):
self.alias_table[name] = (nargs, cmd)

def undefine_alias(self, name):
if self.alias_table.has_key(name):
if name in self.alias_table:
del self.alias_table[name]

def validate_alias(self, name, cmd):
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/displaypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def publish(self, source, data, metadata=None):
"""

# The default is to simply write the plain text data using io.stdout.
if data.has_key('text/plain'):
if 'text/plain' in data:
print(data['text/plain'], file=io.stdout)

def clear_output(self, stdout=True, stderr=True, other=True):
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/magics/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class DataIsObject(Exception): pass

if opts_prev:
args = '_%s' % last_call[0]
if not shell.user_ns.has_key(args):
if args not in shell.user_ns:
args = last_call[1]

# use last_call to remember the state of the previous call, but don't
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/magics/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def prun(self, parameter_s='', cell=None, user_mode=True,
print '\n*** Profile printout saved to text file',\
repr(text_file)+'.',sys_exit

if opts.has_key('r'):
if 'r' in opts:
return stats
else:
return None
Expand Down
6 changes: 3 additions & 3 deletions IPython/core/magics/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ def psearch(self, parameter_s=''):
psearch = shell.inspector.psearch

# select case options
if opts.has_key('i'):
if 'i' in opts:
ignore_case = True
elif opts.has_key('c'):
elif 'c' in opts:
ignore_case = False
else:
ignore_case = not shell.wildcards_case_sensitive
Expand Down Expand Up @@ -656,7 +656,7 @@ def reset_selective(self, parameter_s=''):

opts, regex = self.parse_options(parameter_s,'f')

if opts.has_key('f'):
if 'f' in opts:
ans = True
else:
try:
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, config=None):
def register_plugin(self, name, plugin):
if not isinstance(plugin, Plugin):
raise TypeError('Expected Plugin, got: %r' % plugin)
if self.plugins.has_key(name):
if name in self.plugins:
raise KeyError('Plugin with name already exists: %r' % name)
self.plugins[name] = plugin

Expand Down
4 changes: 2 additions & 2 deletions IPython/core/ultratb.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ def linereader(file=file, lnum=[lnum], getline=linecache.getline):
for name_full in unique_names:
name_base = name_full.split('.',1)[0]
if name_base in frame.f_code.co_varnames:
if locals.has_key(name_base):
if name_base in locals:
try:
value = repr(eval(name_full,locals))
except:
Expand All @@ -901,7 +901,7 @@ def linereader(file=file, lnum=[lnum], getline=linecache.getline):
value = undefined
name = tpl_local_var % name_full
else:
if frame.f_globals.has_key(name_base):
if name_base in frame.f_globals:
try:
value = repr(eval(name_full,frame.f_globals))
except:
Expand Down
6 changes: 3 additions & 3 deletions IPython/extensions/storemagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def store(self, parameter_s=''):
ip = self.shell
db = ip.db
# delete
if opts.has_key('d'):
if 'd' in opts:
try:
todel = args[0]
except IndexError:
Expand All @@ -130,11 +130,11 @@ def store(self, parameter_s=''):
except:
raise UsageError("Can't delete variable '%s'" % todel)
# reset
elif opts.has_key('z'):
elif 'z' in opts:
for k in db.keys('autorestore/*'):
del db[k]

elif opts.has_key('r'):
elif 'r' in opts:
refresh_variables(ip)


Expand Down
2 changes: 1 addition & 1 deletion IPython/external/pexpect/_pexpect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,7 @@ def which (filename):
if os.access (filename, os.X_OK):
return filename

if not os.environ.has_key('PATH') or os.environ['PATH'] == '':
if 'PATH' not in os.environ or os.environ['PATH'] == '':
p = os.defpath
else:
p = os.environ['PATH']
Expand Down
8 changes: 4 additions & 4 deletions IPython/frontend/qt/console/ipython_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,13 @@ def _handle_pyout(self, msg):
content = msg['content']
prompt_number = content.get('execution_count', 0)
data = content['data']
if data.has_key('text/html'):
if 'text/html' in data:
self._append_plain_text(self.output_sep, True)
self._append_html(self._make_out_prompt(prompt_number), True)
html = data['text/html']
self._append_plain_text('\n', True)
self._append_html(html + self.output_sep2, True)
elif data.has_key('text/plain'):
elif 'text/plain' in data:
self._append_plain_text(self.output_sep, True)
self._append_html(self._make_out_prompt(prompt_number), True)
text = data['text/plain']
Expand All @@ -245,10 +245,10 @@ def _handle_display_data(self, msg):
metadata = msg['content']['metadata']
# In the regular IPythonWidget, we simply print the plain text
# representation.
if data.has_key('text/html'):
if 'text/html' in data:
html = data['text/html']
self._append_html(html, True)
elif data.has_key('text/plain'):
elif 'text/plain' in data:
text = data['text/plain']
self._append_plain_text(text, True)
# This newline seems to be needed for text and html output.
Expand Down
12 changes: 6 additions & 6 deletions IPython/frontend/qt/console/rich_ipython_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ def _handle_pyout(self, msg):
content = msg['content']
prompt_number = content.get('execution_count', 0)
data = content['data']
if data.has_key('image/svg+xml'):
if 'image/svg+xml' in data:
self._pre_image_append(msg, prompt_number)
self._append_svg(data['image/svg+xml'], True)
self._append_html(self.output_sep2, True)
elif data.has_key('image/png'):
elif 'image/png' in data:
self._pre_image_append(msg, prompt_number)
self._append_png(decodestring(data['image/png'].encode('ascii')), True)
self._append_html(self.output_sep2, True)
elif data.has_key('image/jpeg') and self._jpg_supported:
elif 'image/jpeg' in data and self._jpg_supported:
self._pre_image_append(msg, prompt_number)
self._append_jpg(decodestring(data['image/jpeg'].encode('ascii')), True)
self._append_html(self.output_sep2, True)
Expand All @@ -142,17 +142,17 @@ def _handle_display_data(self, msg):
metadata = msg['content']['metadata']
# Try to use the svg or html representations.
# FIXME: Is this the right ordering of things to try?
if data.has_key('image/svg+xml'):
if 'image/svg+xml' in data:
self.log.debug("display: %s", msg.get('content', ''))
svg = data['image/svg+xml']
self._append_svg(svg, True)
elif data.has_key('image/png'):
elif 'image/png' in data:
self.log.debug("display: %s", msg.get('content', ''))
# PNG data is base64 encoded as it passes over the network
# in a JSON structure so we decode it.
png = decodestring(data['image/png'].encode('ascii'))
self._append_png(png, True)
elif data.has_key('image/jpeg') and self._jpg_supported:
elif 'image/jpeg' in data and self._jpg_supported:
self.log.debug("display: %s", msg.get('content', ''))
jpg = decodestring(data['image/jpeg'].encode('ascii'))
self._append_jpg(jpg, True)
Expand Down
2 changes: 1 addition & 1 deletion IPython/lib/guisupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def get_app_wx(*args, **kwargs):
import wx
app = wx.GetApp()
if app is None:
if not kwargs.has_key('redirect'):
if 'redirect' not in kwargs:
kwargs['redirect'] = False
app = wx.PySimpleApp(*args, **kwargs)
return app
Expand Down
8 changes: 4 additions & 4 deletions IPython/lib/inputhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def clear_app_refs(self, gui=None):
"""
if gui is None:
self._apps = {}
elif self._apps.has_key(gui):
elif gui in self._apps:
del self._apps[gui]

def enable_wx(self, app=None):
Expand Down Expand Up @@ -225,7 +225,7 @@ def disable_wx(self):

This merely sets PyOS_InputHook to NULL.
"""
if self._apps.has_key(GUI_WX):
if GUI_WX in self._apps:
self._apps[GUI_WX]._in_event_loop = False
self.clear_inputhook()

Expand Down Expand Up @@ -265,7 +265,7 @@ def disable_qt4(self):

This merely sets PyOS_InputHook to NULL.
"""
if self._apps.has_key(GUI_QT4):
if GUI_QT4 in self._apps:
self._apps[GUI_QT4]._in_event_loop = False
self.clear_inputhook()

Expand Down Expand Up @@ -364,7 +364,7 @@ def enable_glut(self, app=None):
glut_close, glut_display, \
glut_idle, inputhook_glut

if not self._apps.has_key( GUI_GLUT ):
if GUI_GLUT not in self._apps:
glut.glutInit( sys.argv )
glut.glutInitDisplayMode( glut_display_mode )
# This is specific to freeglut
Expand Down
2 changes: 1 addition & 1 deletion IPython/parallel/controller/dictdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _extract_subdict(self, rec, keys):

def add_record(self, msg_id, rec):
"""Add a new Task Record, by msg_id."""
if self._records.has_key(msg_id):
if msg_id in self._records:
raise KeyError("Already have msg_id %r"%(msg_id))
self._records[msg_id] = rec

Expand Down
4 changes: 2 additions & 2 deletions IPython/parallel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ def _pull(keys):
user_ns = globals()
if isinstance(keys, (list,tuple, set)):
for key in keys:
if not user_ns.has_key(key):
if key not in user_ns:
raise NameError("name '%s' is not defined"%key)
return map(user_ns.get, keys)
else:
if not user_ns.has_key(keys):
if keys not in user_ns:
raise NameError("name '%s' is not defined"%keys)
return user_ns.get(keys)

Expand Down
6 changes: 3 additions & 3 deletions IPython/utils/ipstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __setitem__(self, key, value):
...
this is not allowed
"""
if not self._allownew and not self.has_key(key):
if not self._allownew and key not in self:
raise KeyError(
"can't create new attribute %s when allow_new_attr(False)" % key)
dict.__setitem__(self, key, value)
Expand Down Expand Up @@ -212,7 +212,7 @@ def __isub__(self,other):
{'b': 30}
"""
for k in other.keys():
if self.has_key(k):
if k in self:
del self[k]
return self

Expand Down Expand Up @@ -262,7 +262,7 @@ def hasattr(self, key):
>>> s.hasattr('get')
False
"""
return self.has_key(key)
return key in self

def allow_new_attr(self, allow = True):
"""Set whether new attributes can be created in this Struct.
Expand Down
4 changes: 2 additions & 2 deletions IPython/utils/traitlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def _notify_trait(self, name, old_value, new_value):


def _add_notifiers(self, handler, name):
if not self._trait_notifiers.has_key(name):
if name not in self._trait_notifiers:
nlist = []
self._trait_notifiers[name] = nlist
else:
Expand All @@ -474,7 +474,7 @@ def _add_notifiers(self, handler, name):
nlist.append(handler)

def _remove_notifiers(self, handler, name):
if self._trait_notifiers.has_key(name):
if name in self._trait_notifiers:
nlist = self._trait_notifiers[name]
try:
index = nlist.index(handler)
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,11 @@ def run(self):
# so we explicitly disable some 2to3 fixes to be sure we aren't forgetting
# anything.
setuptools_extra_args['use_2to3_exclude_fixers'] = [
'lib2to3.fixes.fix_except',
'lib2to3.fixes.fix_apply',
'lib2to3.fixes.fix_repr',
'lib2to3.fixes.fix_except',
'lib2to3.fixes.fix_has_key',
'lib2to3.fixes.fix_next',
'lib2to3.fixes.fix_repr',
]
from setuptools.command.build_py import build_py
setup_args['cmdclass'] = {'build_py': record_commit_info('IPython', build_cmd=build_py)}
Expand Down