diff --git a/IPython/core/builtin_trap.py b/IPython/core/builtin_trap.py index b3c9fdf..b9d4e95 100644 --- a/IPython/core/builtin_trap.py +++ b/IPython/core/builtin_trap.py @@ -20,7 +20,7 @@ Authors: from traitlets.config.configurable import Configurable -from IPython.utils.py3compat import builtin_mod, iteritems +from IPython.utils.py3compat import builtin_mod from traitlets import Instance #----------------------------------------------------------------------------- @@ -90,14 +90,14 @@ class BuiltinTrap(Configurable): """Store ipython references in the __builtin__ namespace.""" add_builtin = self.add_builtin - for name, func in iteritems(self.auto_builtins): + for name, func in self.auto_builtins.items(): add_builtin(name, func) def deactivate(self): """Remove any builtins which might have been added by add_builtins, or restore overwritten ones to their previous values.""" remove_builtin = self.remove_builtin - for key, val in iteritems(self._orig_builtins): + for key, val in self._orig_builtins.items(): remove_builtin(key, val) self._orig_builtins.clear() self._builtins_added = False diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index cce24de..9d2c325 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -68,7 +68,7 @@ from IPython.paths import get_ipython_dir from IPython.utils.path import get_home_dir, get_py_filename, ensure_dir_exists from IPython.utils.process import system, getoutput from IPython.utils.py3compat import (builtin_mod, unicode_type, string_types, - with_metaclass, iteritems) + with_metaclass) from IPython.utils.strdispatch import StrDispatch from IPython.utils.syspathcontext import prepended_to_syspath from IPython.utils.text import format_screen, LSString, SList, DollarFormatter @@ -733,7 +733,7 @@ class InteractiveShell(SingletonConfigurable): def restore_sys_module_state(self): """Restore the state of the sys module.""" try: - for k, v in iteritems(self._orig_sys_module_state): + for k, v in self._orig_sys_module_state.items(): setattr(sys, k, v) except AttributeError: pass @@ -1255,7 +1255,7 @@ class InteractiveShell(SingletonConfigurable): # Also check in output history ns_refs.append(self.history_manager.output_hist) for ns in ns_refs: - to_delete = [n for n, o in iteritems(ns) if o is obj] + to_delete = [n for n, o in ns.items() if o is obj] for name in to_delete: del ns[name] @@ -1347,7 +1347,7 @@ class InteractiveShell(SingletonConfigurable): variables : dict A dictionary mapping object names (as strings) to the objects. """ - for name, obj in iteritems(variables): + for name, obj in variables.items(): if name in self.user_ns and self.user_ns[name] is obj: del self.user_ns[name] self.user_ns_hidden.pop(name, None) @@ -2382,7 +2382,7 @@ class InteractiveShell(SingletonConfigurable): user_ns = self.user_ns global_ns = self.user_global_ns - for key, expr in iteritems(expressions): + for key, expr in expressions.items(): try: value = self._format_user_obj(eval(expr, global_ns, user_ns)) except: diff --git a/IPython/core/magic.py b/IPython/core/magic.py index e139bed..7c1e90c 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -24,7 +24,7 @@ from IPython.core.inputsplitter import ESC_MAGIC, ESC_MAGIC2 from decorator import decorator from IPython.utils.ipstruct import Struct from IPython.utils.process import arg_split -from IPython.utils.py3compat import string_types, iteritems +from IPython.utils.py3compat import string_types from IPython.utils.text import dedent from traitlets import Bool, Dict, Instance, observe from logging import error @@ -344,7 +344,7 @@ class MagicsManager(Configurable): docs = {} for m_type in self.magics: m_docs = {} - for m_name, m_func in iteritems(self.magics[m_type]): + for m_name, m_func in self.magics[m_type].items(): if m_func.__doc__: if brief: m_docs[m_name] = m_func.__doc__.split('\n', 1)[0] @@ -510,7 +510,7 @@ class Magics(Configurable): for mtype in magic_kinds: tab = self.magics[mtype] = {} cls_tab = class_magics[mtype] - for magic_name, meth_name in iteritems(cls_tab): + for magic_name, meth_name in cls_tab.items(): if isinstance(meth_name, string_types): # it's a method name, grab it tab[magic_name] = getattr(self, meth_name) diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py index 78a0372..eedab6d 100644 --- a/IPython/core/magics/execution.py +++ b/IPython/core/magics/execution.py @@ -36,7 +36,7 @@ from IPython.core.magic import (Magics, magics_class, line_magic, cell_magic, line_cell_magic, on_off, needs_local_scope) from IPython.testing.skipdoctest import skip_doctest from IPython.utils import py3compat -from IPython.utils.py3compat import builtin_mod, iteritems, PY3 +from IPython.utils.py3compat import builtin_mod, PY3 from IPython.utils.contexts import preserve_keys from IPython.utils.capture import capture_output from IPython.utils.ipstruct import Struct @@ -1271,8 +1271,7 @@ python-profiler package from non-free.""") """ opts,args = self.parse_options(parameter_s,'rq',mode='list') if not args: # List existing macros - return sorted(k for k,v in iteritems(self.shell.user_ns) if\ - isinstance(v, Macro)) + return sorted(k for k,v in self.shell.user_ns.items() if isinstance(v, Macro)) if len(args) == 1: raise UsageError( "%macro insufficient args; usage '%macro name n1-n2 n3-4...") diff --git a/IPython/lib/pretty.py b/IPython/lib/pretty.py index 3eaa0b3..6e31daa 100644 --- a/IPython/lib/pretty.py +++ b/IPython/lib/pretty.py @@ -771,7 +771,6 @@ except AttributeError: # Python 3 _type_pprinters[slice] = _repr_pprint try: - _type_pprinters[xrange] = _repr_pprint _type_pprinters[long] = _repr_pprint _type_pprinters[unicode] = _repr_pprint except NameError: diff --git a/IPython/utils/data.py b/IPython/utils/data.py index 308a692..bf70cf8 100644 --- a/IPython/utils/data.py +++ b/IPython/utils/data.py @@ -9,7 +9,6 @@ # the file COPYING, distributed as part of this software. #----------------------------------------------------------------------------- -from .py3compat import xrange def uniq_stable(elems): """uniq_stable(elems) -> list @@ -32,6 +31,6 @@ def flatten(seq): def chop(seq, size): """Chop a sequence into chunks of the given size.""" - return [seq[i:i+size] for i in xrange(0,len(seq),size)] + return [seq[i:i+size] for i in range(0,len(seq),size)] diff --git a/IPython/utils/text.py b/IPython/utils/text.py index 0ad1c8d..2c39dee 100644 --- a/IPython/utils/text.py +++ b/IPython/utils/text.py @@ -619,10 +619,10 @@ def _col_chunks(l, max_rows, row_first=False): """Yield successive max_rows-sized column chunks from l.""" if row_first: ncols = (len(l) // max_rows) + (len(l) % max_rows > 0) - for i in py3compat.xrange(ncols): - yield [l[j] for j in py3compat.xrange(i, len(l), ncols)] + for i in range(ncols): + yield [l[j] for j in range(i, len(l), ncols)] else: - for i in py3compat.xrange(0, len(l), max_rows): + for i in range(0, len(l), max_rows): yield l[i:(i + max_rows)] diff --git a/IPython/utils/timing.py b/IPython/utils/timing.py index 99b7bbc..3d4d9f8 100644 --- a/IPython/utils/timing.py +++ b/IPython/utils/timing.py @@ -16,8 +16,6 @@ Utilities for timing code execution. import time -from .py3compat import xrange - #----------------------------------------------------------------------------- # Code #----------------------------------------------------------------------------- @@ -89,7 +87,7 @@ def timings_out(reps,func,*args,**kw): out = func(*args,**kw) tot_time = clock()-start else: - rng = xrange(reps-1) # the last time is executed separately to store output + rng = range(reps-1) # the last time is executed separately to store output start = clock() for dummy in rng: func(*args,**kw) out = func(*args,**kw) # one last time diff --git a/IPython/utils/wildcard.py b/IPython/utils/wildcard.py index d22491b..cbef8c5 100644 --- a/IPython/utils/wildcard.py +++ b/IPython/utils/wildcard.py @@ -18,7 +18,6 @@ import re import types from IPython.utils.dir2 import dir2 -from .py3compat import iteritems def create_typestr2type_dicts(dont_include_in_type2typestr=["lambda"]): """Return dictionaries mapping lower case typename (e.g. 'tuple') to type @@ -83,7 +82,7 @@ def filter_ns(ns, name_pattern="*", type_pattern="all", ignore_case=True, reg = re.compile(pattern+"$") # Check each one matches regex; shouldn't be hidden; of correct type. - return dict((key,obj) for key, obj in iteritems(ns) if reg.match(key) \ + return dict((key,obj) for key, obj in ns.items() if reg.match(key) \ and show_hidden(key, show_all) \ and is_type(obj, type_pattern) ) @@ -103,10 +102,10 @@ def list_namespace(namespace, type_pattern, filter, ignore_case=False, show_all= type_pattern="all", ignore_case=ignore_case, show_all=show_all) results = {} - for name, obj in iteritems(filtered): + for name, obj in filtered.items(): ns = list_namespace(dict_dir(obj), type_pattern, ".".join(pattern_list[1:]), ignore_case=ignore_case, show_all=show_all) - for inner_name, inner_obj in iteritems(ns): + for inner_name, inner_obj in ns.items(): results["%s.%s"%(name,inner_name)] = inner_obj return results