Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert iteritems() to items() #10105

Merged
merged 13 commits into from Jan 6, 2017
3 changes: 1 addition & 2 deletions IPython/core/alias.py
Expand Up @@ -27,7 +27,6 @@
from traitlets.config.configurable import Configurable
from IPython.core.error import UsageError

from IPython.utils.py3compat import string_types
from traitlets import List, Instance
from logging import error

Expand Down Expand Up @@ -148,7 +147,7 @@ def validate(self):
raise InvalidAliasError("The name %s can't be aliased "
"because it is another magic command." % self.name)

if not (isinstance(self.cmd, string_types)):
if not (isinstance(self.cmd, str)):
raise InvalidAliasError("An alias command must be a string, "
"got: %r" % self.cmd)

Expand Down
4 changes: 2 additions & 2 deletions IPython/core/application.py
Expand Up @@ -126,7 +126,7 @@ def _config_file_name_changed(self, change):
config_file_paths = List(Unicode())
@default('config_file_paths')
def _config_file_paths_default(self):
return [py3compat.getcwd()]
return [os.getcwd()]

extra_config_file = Unicode(
help="""Path to an extra config file to load.
Expand Down Expand Up @@ -215,7 +215,7 @@ def __init__(self, **kwargs):
super(BaseIPythonApplication, self).__init__(**kwargs)
# ensure current working directory exists
try:
py3compat.getcwd()
os.getcwd()
except:
# exit if cwd doesn't exist
self.log.error("Current working directory doesn't exist.")
Expand Down
6 changes: 3 additions & 3 deletions IPython/core/builtin_trap.py
Expand Up @@ -20,7 +20,7 @@

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

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -90,14 +90,14 @@ def activate(self):
"""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
6 changes: 3 additions & 3 deletions IPython/core/completer.py
Expand Up @@ -35,7 +35,7 @@
from IPython.utils.decorators import undoc
from IPython.utils.dir2 import dir2, get_real_method
from IPython.utils.process import arg_split
from IPython.utils.py3compat import builtin_mod, string_types, PY3, cast_unicode_py2
from IPython.utils.py3compat import builtin_mod, PY3, cast_unicode_py2
from traitlets import Bool, Enum, observe

from functools import wraps
Expand Down Expand Up @@ -423,14 +423,14 @@ def get__all__entries(obj):
except:
return []

return [cast_unicode_py2(w) for w in words if isinstance(w, string_types)]
return [cast_unicode_py2(w) for w in words if isinstance(w, str)]


def match_dict_keys(keys, prefix, delims):
"""Used by dict_key_matches, matching the prefix to a list of keys"""
if not prefix:
return None, 0, [repr(k) for k in keys
if isinstance(k, (string_types, bytes))]
if isinstance(k, (str, bytes))]
quote_match = re.search('["\']', prefix)
quote = quote_match.group()
try:
Expand Down
5 changes: 2 additions & 3 deletions IPython/core/completerlib.py
Expand Up @@ -39,7 +39,6 @@
from IPython.core.completer import expand_user, compress_user
from IPython.core.error import TryNext
from IPython.utils._process_common import arg_split
from IPython.utils.py3compat import string_types

# FIXME: this should be pulled in with the right call via the component system
from IPython import get_ipython
Expand Down Expand Up @@ -169,7 +168,7 @@ def try_import(mod, only_modules=False):
completions.extend(getattr(m, '__all__', []))
if m_is_init:
completions.extend(module_list(os.path.dirname(m.__file__)))
completions = {c for c in completions if isinstance(c, string_types)}
completions = {c for c in completions if isinstance(c, str)}
completions.discard('__init__')
return list(completions)

Expand All @@ -193,7 +192,7 @@ def quick_completer(cmd, completions):
[d:\ipython]|3> foo ba
"""

if isinstance(completions, string_types):
if isinstance(completions, str):
completions = completions.split()

def do_complete(self, event):
Expand Down
6 changes: 3 additions & 3 deletions IPython/core/crashhandler.py
Expand Up @@ -27,7 +27,7 @@
from IPython.core import ultratb
from IPython.core.release import author_email
from IPython.utils.sysinfo import sys_info
from IPython.utils.py3compat import input, getcwd
from IPython.utils.py3compat import input

#-----------------------------------------------------------------------------
# Code
Expand Down Expand Up @@ -139,9 +139,9 @@ def __call__(self, etype, evalue, etb):
try:
rptdir = self.app.ipython_dir
except:
rptdir = getcwd()
rptdir = os.getcwd()
if rptdir is None or not os.path.isdir(rptdir):
rptdir = getcwd()
rptdir = os.getcwd()
report_name = os.path.join(rptdir,self.crash_report_fname)
# write the report filename into the instance dict so it can get
# properly expanded out in the user message template
Expand Down
25 changes: 12 additions & 13 deletions IPython/core/display.py
Expand Up @@ -18,8 +18,7 @@
import sys
import warnings

from IPython.utils.py3compat import (string_types, cast_bytes_py2, cast_unicode,
unicode_type)
from IPython.utils.py3compat import cast_bytes_py2, cast_unicode
from IPython.testing.skipdoctest import skip_doctest

__all__ = ['display', 'display_pretty', 'display_html', 'display_markdown',
Expand Down Expand Up @@ -481,7 +480,7 @@ def __init__(self, data=None, url=None, filename=None):
filename : unicode
Path to a local file to load the data from.
"""
if data is not None and isinstance(data, string_types):
if data is not None and isinstance(data, str):
if data.startswith('http') and url is None:
url = data
filename = None
Expand All @@ -493,7 +492,7 @@ def __init__(self, data=None, url=None, filename=None):

self.data = data
self.url = url
self.filename = None if filename is None else unicode_type(filename)
self.filename = filename

self.reload()
self._check_data()
Expand Down Expand Up @@ -539,7 +538,7 @@ def reload(self):
class TextDisplayObject(DisplayObject):
"""Validate that display data is text"""
def _check_data(self):
if self.data is not None and not isinstance(self.data, string_types):
if self.data is not None and not isinstance(self.data, str):
raise TypeError("%s expects text, not %r" % (self.__class__.__name__, self.data))

class Pretty(TextDisplayObject):
Expand Down Expand Up @@ -657,7 +656,7 @@ def data(self):

@data.setter
def data(self, data):
if isinstance(data, string_types):
if isinstance(data, str):
warnings.warn("JSON expects JSONable dict or list, not JSON strings")
data = json.loads(data)
self._data = data
Expand Down Expand Up @@ -715,11 +714,11 @@ def __init__(self, data=None, url=None, filename=None, lib=None, css=None):
The full URLs of the css files should be given. A single css URL
can also be given as a string.
"""
if isinstance(lib, string_types):
if isinstance(lib, str):
lib = [lib]
elif lib is None:
lib = []
if isinstance(css, string_types):
if isinstance(css, str):
css = [css]
elif css is None:
css = []
Expand Down Expand Up @@ -848,7 +847,7 @@ def __init__(self, data=None, url=None, filename=None, format=None,
ext = self._find_ext(url)
elif data is None:
raise ValueError("No image data found. Expecting filename, url, or data.")
elif isinstance(data, string_types) and (
elif isinstance(data, str) and (
data.startswith('http') or _safe_exists(data)
):
ext = self._find_ext(data)
Expand Down Expand Up @@ -877,7 +876,7 @@ def __init__(self, data=None, url=None, filename=None, format=None,
# jpg->jpeg
format = self._FMT_JPEG

self.format = unicode_type(format).lower()
self.format = format.lower()
self.embed = embed if embed is not None else (url is None)

if self.embed and self.format not in self._ACCEPTABLE_EMBEDDINGS:
Expand Down Expand Up @@ -954,7 +953,7 @@ def _repr_jpeg_(self):
return self._data_and_metadata()

def _find_ext(self, s):
return unicode_type(s.split('.')[-1].lower())
return s.split('.')[-1].lower()

class Video(DisplayObject):

Expand Down Expand Up @@ -999,7 +998,7 @@ def __init__(self, data=None, url=None, filename=None, embed=False, mimetype=Non
Video('path/to/video.mp4', embed=True)
Video(b'raw-videodata', embed=True)
"""
if url is None and isinstance(data, string_types) and data.startswith(('http:', 'https:')):
if url is None and isinstance(data, str) and data.startswith(('http:', 'https:')):
url = data
data = None
elif os.path.exists(data):
Expand Down Expand Up @@ -1038,7 +1037,7 @@ def _repr_html_(self):
video = f.read()
else:
video = self.data
if isinstance(video, unicode_type):
if isinstance(video, str):
# unicode input is already b64-encoded
b64_video = video
else:
Expand Down
18 changes: 9 additions & 9 deletions IPython/core/formatters.py
Expand Up @@ -29,7 +29,7 @@
default, observe,
)
from IPython.utils.py3compat import (
with_metaclass, string_types, unicode_type,
with_metaclass
)


Expand Down Expand Up @@ -276,7 +276,7 @@ class BaseFormatter(Configurable):
"""

format_type = Unicode('text/plain')
_return_type = string_types
_return_type = str

enabled = Bool(True).tag(config=True)

Expand Down Expand Up @@ -376,7 +376,7 @@ def lookup_by_type(self, typ):
------
KeyError if the type has not been registered.
"""
if isinstance(typ, string_types):
if isinstance(typ, str):
typ_key = tuple(typ.rsplit('.',1))
if typ_key not in self.deferred_printers:
# We may have it cached in the type map. We will have to
Expand Down Expand Up @@ -419,7 +419,7 @@ def for_type(self, typ, func=None):
this will be the previous value (to enable restoring later).
"""
# if string given, interpret as 'pkg.module.class_name'
if isinstance(typ, string_types):
if isinstance(typ, str):
type_module, type_name = typ.rsplit('.', 1)
return self.for_type_by_name(type_module, type_name, func)

Expand Down Expand Up @@ -491,7 +491,7 @@ def pop(self, typ, default=_raise_key_error):
KeyError if the type is not registered and default is not specified.
"""

if isinstance(typ, string_types):
if isinstance(typ, str):
typ_key = tuple(typ.rsplit('.',1))
if typ_key not in self.deferred_printers:
# We may have it cached in the type map. We will have to
Expand Down Expand Up @@ -737,7 +737,7 @@ class PNGFormatter(BaseFormatter):

print_method = ObjectName('_repr_png_')

_return_type = (bytes, unicode_type)
_return_type = (bytes, str)


class JPEGFormatter(BaseFormatter):
Expand All @@ -755,7 +755,7 @@ class JPEGFormatter(BaseFormatter):

print_method = ObjectName('_repr_jpeg_')

_return_type = (bytes, unicode_type)
_return_type = (bytes, str)


class LatexFormatter(BaseFormatter):
Expand Down Expand Up @@ -804,7 +804,7 @@ def _check_return(self, r, obj):
r, md = r

# handle deprecated JSON-as-string form from IPython < 3
if isinstance(r, string_types):
if isinstance(r, str):
warnings.warn("JSON expects JSONable list/dict containers, not JSON strings",
FormatterWarning)
r = json.loads(r)
Expand Down Expand Up @@ -846,7 +846,7 @@ class PDFFormatter(BaseFormatter):

print_method = ObjectName('_repr_pdf_')

_return_type = (bytes, unicode_type)
_return_type = (bytes, str)

class IPythonDisplayFormatter(BaseFormatter):
"""A Formatter for objects that know how to display themselves.
Expand Down
4 changes: 2 additions & 2 deletions IPython/core/history.py
Expand Up @@ -487,7 +487,7 @@ class HistoryManager(HistoryAccessor):
@default('dir_hist')
def _dir_hist_default(self):
try:
return [py3compat.getcwd()]
return [os.getcwd()]
except OSError:
return []

Expand Down Expand Up @@ -593,7 +593,7 @@ def reset(self, new_session=True):
optionally open a new session."""
self.output_hist.clear()
# The directory history can't be completely empty
self.dir_hist[:] = [py3compat.getcwd()]
self.dir_hist[:] = [os.getcwd()]

if new_session:
if self.session_number:
Expand Down