Skip to content

Commit

Permalink
Various Python 3 fixes in IPython.utils
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Sep 7, 2011
1 parent 5299658 commit 2467d2e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
5 changes: 4 additions & 1 deletion IPython/utils/jsonutil.py
Expand Up @@ -16,6 +16,9 @@
import types
from datetime import datetime

from IPython.utils import py3compat
next_attr_name = '__next__' if py3compat.PY3 else 'next'

#-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -134,7 +137,7 @@ def json_clean(obj):
return obj.decode(sys.getdefaultencoding(), 'replace')

if isinstance(obj, container_to_list) or (
hasattr(obj, '__iter__') and hasattr(obj, 'next')):
hasattr(obj, '__iter__') and hasattr(obj, next_attr_name)):
obj = list(obj)

if isinstance(obj, list):
Expand Down
2 changes: 1 addition & 1 deletion IPython/utils/process.py
Expand Up @@ -66,7 +66,7 @@ def find_cmd(cmd):
except OSError:
raise FindCmdError('command could not be found: %s' % cmd)
# which returns empty if not found
if path == '':
if path == b'':
raise FindCmdError('command could not be found: %s' % cmd)
return os.path.abspath(path)

Expand Down
11 changes: 9 additions & 2 deletions IPython/utils/tests/test_path.py
Expand Up @@ -31,17 +31,24 @@
from IPython.testing.decorators import skip_if_not_win32, skip_win32
from IPython.testing.tools import make_tempfile
from IPython.utils import path, io
from IPython.utils import py3compat

# Platform-dependent imports
try:
import _winreg as wreg
except ImportError:
#Fake _winreg module on none windows platforms
import new
sys.modules["_winreg"] = new.module("_winreg")
import types
wr_name = "winreg" if py3compat.PY3 else "_winreg"
sys.modules[wr_name] = types.ModuleType(wr_name)
import _winreg as wreg
#Add entries that needs to be stubbed by the testing code
(wreg.OpenKey, wreg.QueryValueEx,) = (None, None)

try:
reload
except NameError: # Python 3
from imp import reload

#-----------------------------------------------------------------------------
# Globals
Expand Down
2 changes: 1 addition & 1 deletion IPython/utils/tests/test_process.py
Expand Up @@ -37,7 +37,7 @@ def test_find_cmd_python():
def test_find_cmd_ls():
"""Make sure we can find the full path to ls."""
path = find_cmd('ls')
nt.assert_true(path.endswith('ls'))
nt.assert_true(path.endswith(b'ls'))


def has_pywin32():
Expand Down
4 changes: 2 additions & 2 deletions IPython/utils/text.py
Expand Up @@ -587,10 +587,10 @@ class EvalFormatter(Formatter):
--------
In [1]: f = EvalFormatter()
In [2]: f.format('{n/4}', n=8)
In [2]: f.format('{n//4}', n=8)
Out[2]: '2'
In [3]: f.format('{range(3)}')
In [3]: f.format('{list(range(3))}')
Out[3]: '[0, 1, 2]'
In [4]: f.format('{3*2}')
Expand Down
4 changes: 3 additions & 1 deletion IPython/utils/traitlets.py
Expand Up @@ -882,7 +882,9 @@ def validate(self, obj, value):
except:
self.error(obj, value)

if not py3compat.PY3:
if py3compat.PY3:
Long, CLong = Int, CInt
else:
class Long(TraitType):
"""A long integer trait."""

Expand Down

0 comments on commit 2467d2e

Please sign in to comment.