Show More
@@ -27,7 +27,6 b' import sys' | |||||
27 | from traitlets.config.configurable import Configurable |
|
27 | from traitlets.config.configurable import Configurable | |
28 | from IPython.core.error import UsageError |
|
28 | from IPython.core.error import UsageError | |
29 |
|
29 | |||
30 | from IPython.utils.py3compat import string_types |
|
|||
31 | from traitlets import List, Instance |
|
30 | from traitlets import List, Instance | |
32 | from logging import error |
|
31 | from logging import error | |
33 |
|
32 | |||
@@ -148,7 +147,7 b' class Alias(object):' | |||||
148 | raise InvalidAliasError("The name %s can't be aliased " |
|
147 | raise InvalidAliasError("The name %s can't be aliased " | |
149 | "because it is another magic command." % self.name) |
|
148 | "because it is another magic command." % self.name) | |
150 |
|
149 | |||
151 |
if not (isinstance(self.cmd, str |
|
150 | if not (isinstance(self.cmd, str)): | |
152 | raise InvalidAliasError("An alias command must be a string, " |
|
151 | raise InvalidAliasError("An alias command must be a string, " | |
153 | "got: %r" % self.cmd) |
|
152 | "got: %r" % self.cmd) | |
154 |
|
153 |
@@ -35,7 +35,7 b' from IPython.utils import generics' | |||||
35 | from IPython.utils.decorators import undoc |
|
35 | from IPython.utils.decorators import undoc | |
36 | from IPython.utils.dir2 import dir2, get_real_method |
|
36 | from IPython.utils.dir2 import dir2, get_real_method | |
37 | from IPython.utils.process import arg_split |
|
37 | from IPython.utils.process import arg_split | |
38 |
from IPython.utils.py3compat import builtin_mod, |
|
38 | from IPython.utils.py3compat import builtin_mod, PY3, cast_unicode_py2 | |
39 | from traitlets import Bool, Enum, observe |
|
39 | from traitlets import Bool, Enum, observe | |
40 |
|
40 | |||
41 | from functools import wraps |
|
41 | from functools import wraps | |
@@ -423,14 +423,14 b' def get__all__entries(obj):' | |||||
423 | except: |
|
423 | except: | |
424 | return [] |
|
424 | return [] | |
425 |
|
425 | |||
426 |
return [cast_unicode_py2(w) for w in words if isinstance(w, str |
|
426 | return [cast_unicode_py2(w) for w in words if isinstance(w, str)] | |
427 |
|
427 | |||
428 |
|
428 | |||
429 | def match_dict_keys(keys, prefix, delims): |
|
429 | def match_dict_keys(keys, prefix, delims): | |
430 | """Used by dict_key_matches, matching the prefix to a list of keys""" |
|
430 | """Used by dict_key_matches, matching the prefix to a list of keys""" | |
431 | if not prefix: |
|
431 | if not prefix: | |
432 | return None, 0, [repr(k) for k in keys |
|
432 | return None, 0, [repr(k) for k in keys | |
433 |
if isinstance(k, (str |
|
433 | if isinstance(k, (str, bytes))] | |
434 | quote_match = re.search('["\']', prefix) |
|
434 | quote_match = re.search('["\']', prefix) | |
435 | quote = quote_match.group() |
|
435 | quote = quote_match.group() | |
436 | try: |
|
436 | try: |
@@ -39,7 +39,6 b' from zipimport import zipimporter' | |||||
39 | from IPython.core.completer import expand_user, compress_user |
|
39 | from IPython.core.completer import expand_user, compress_user | |
40 | from IPython.core.error import TryNext |
|
40 | from IPython.core.error import TryNext | |
41 | from IPython.utils._process_common import arg_split |
|
41 | from IPython.utils._process_common import arg_split | |
42 | from IPython.utils.py3compat import string_types |
|
|||
43 |
|
42 | |||
44 | # FIXME: this should be pulled in with the right call via the component system |
|
43 | # FIXME: this should be pulled in with the right call via the component system | |
45 | from IPython import get_ipython |
|
44 | from IPython import get_ipython | |
@@ -169,7 +168,7 b' def try_import(mod, only_modules=False):' | |||||
169 | completions.extend(getattr(m, '__all__', [])) |
|
168 | completions.extend(getattr(m, '__all__', [])) | |
170 | if m_is_init: |
|
169 | if m_is_init: | |
171 | completions.extend(module_list(os.path.dirname(m.__file__))) |
|
170 | completions.extend(module_list(os.path.dirname(m.__file__))) | |
172 |
completions = {c for c in completions if isinstance(c, str |
|
171 | completions = {c for c in completions if isinstance(c, str)} | |
173 | completions.discard('__init__') |
|
172 | completions.discard('__init__') | |
174 | return list(completions) |
|
173 | return list(completions) | |
175 |
|
174 | |||
@@ -193,7 +192,7 b' def quick_completer(cmd, completions):' | |||||
193 | [d:\ipython]|3> foo ba |
|
192 | [d:\ipython]|3> foo ba | |
194 | """ |
|
193 | """ | |
195 |
|
194 | |||
196 |
if isinstance(completions, str |
|
195 | if isinstance(completions, str): | |
197 | completions = completions.split() |
|
196 | completions = completions.split() | |
198 |
|
197 | |||
199 | def do_complete(self, event): |
|
198 | def do_complete(self, event): |
@@ -18,8 +18,7 b' import struct' | |||||
18 | import sys |
|
18 | import sys | |
19 | import warnings |
|
19 | import warnings | |
20 |
|
20 | |||
21 |
from IPython.utils.py3compat import |
|
21 | from IPython.utils.py3compat import cast_bytes_py2, cast_unicode, unicode_type | |
22 | unicode_type) |
|
|||
23 | from IPython.testing.skipdoctest import skip_doctest |
|
22 | from IPython.testing.skipdoctest import skip_doctest | |
24 |
|
23 | |||
25 | __all__ = ['display', 'display_pretty', 'display_html', 'display_markdown', |
|
24 | __all__ = ['display', 'display_pretty', 'display_html', 'display_markdown', | |
@@ -481,7 +480,7 b' class DisplayObject(object):' | |||||
481 | filename : unicode |
|
480 | filename : unicode | |
482 | Path to a local file to load the data from. |
|
481 | Path to a local file to load the data from. | |
483 | """ |
|
482 | """ | |
484 |
if data is not None and isinstance(data, str |
|
483 | if data is not None and isinstance(data, str): | |
485 | if data.startswith('http') and url is None: |
|
484 | if data.startswith('http') and url is None: | |
486 | url = data |
|
485 | url = data | |
487 | filename = None |
|
486 | filename = None | |
@@ -539,7 +538,7 b' class DisplayObject(object):' | |||||
539 | class TextDisplayObject(DisplayObject): |
|
538 | class TextDisplayObject(DisplayObject): | |
540 | """Validate that display data is text""" |
|
539 | """Validate that display data is text""" | |
541 | def _check_data(self): |
|
540 | def _check_data(self): | |
542 |
if self.data is not None and not isinstance(self.data, str |
|
541 | if self.data is not None and not isinstance(self.data, str): | |
543 | raise TypeError("%s expects text, not %r" % (self.__class__.__name__, self.data)) |
|
542 | raise TypeError("%s expects text, not %r" % (self.__class__.__name__, self.data)) | |
544 |
|
543 | |||
545 | class Pretty(TextDisplayObject): |
|
544 | class Pretty(TextDisplayObject): | |
@@ -657,7 +656,7 b' class JSON(DisplayObject):' | |||||
657 |
|
656 | |||
658 | @data.setter |
|
657 | @data.setter | |
659 | def data(self, data): |
|
658 | def data(self, data): | |
660 |
if isinstance(data, str |
|
659 | if isinstance(data, str): | |
661 | warnings.warn("JSON expects JSONable dict or list, not JSON strings") |
|
660 | warnings.warn("JSON expects JSONable dict or list, not JSON strings") | |
662 | data = json.loads(data) |
|
661 | data = json.loads(data) | |
663 | self._data = data |
|
662 | self._data = data | |
@@ -715,11 +714,11 b' class Javascript(TextDisplayObject):' | |||||
715 | The full URLs of the css files should be given. A single css URL |
|
714 | The full URLs of the css files should be given. A single css URL | |
716 | can also be given as a string. |
|
715 | can also be given as a string. | |
717 | """ |
|
716 | """ | |
718 |
if isinstance(lib, str |
|
717 | if isinstance(lib, str): | |
719 | lib = [lib] |
|
718 | lib = [lib] | |
720 | elif lib is None: |
|
719 | elif lib is None: | |
721 | lib = [] |
|
720 | lib = [] | |
722 |
if isinstance(css, str |
|
721 | if isinstance(css, str): | |
723 | css = [css] |
|
722 | css = [css] | |
724 | elif css is None: |
|
723 | elif css is None: | |
725 | css = [] |
|
724 | css = [] | |
@@ -848,7 +847,7 b' class Image(DisplayObject):' | |||||
848 | ext = self._find_ext(url) |
|
847 | ext = self._find_ext(url) | |
849 | elif data is None: |
|
848 | elif data is None: | |
850 | raise ValueError("No image data found. Expecting filename, url, or data.") |
|
849 | raise ValueError("No image data found. Expecting filename, url, or data.") | |
851 |
elif isinstance(data, str |
|
850 | elif isinstance(data, str) and ( | |
852 | data.startswith('http') or _safe_exists(data) |
|
851 | data.startswith('http') or _safe_exists(data) | |
853 | ): |
|
852 | ): | |
854 | ext = self._find_ext(data) |
|
853 | ext = self._find_ext(data) | |
@@ -999,7 +998,7 b' class Video(DisplayObject):' | |||||
999 | Video('path/to/video.mp4', embed=True) |
|
998 | Video('path/to/video.mp4', embed=True) | |
1000 | Video(b'raw-videodata', embed=True) |
|
999 | Video(b'raw-videodata', embed=True) | |
1001 | """ |
|
1000 | """ | |
1002 |
if url is None and isinstance(data, str |
|
1001 | if url is None and isinstance(data, str) and data.startswith(('http:', 'https:')): | |
1003 | url = data |
|
1002 | url = data | |
1004 | data = None |
|
1003 | data = None | |
1005 | elif os.path.exists(data): |
|
1004 | elif os.path.exists(data): |
@@ -29,7 +29,7 b' from traitlets import (' | |||||
29 | default, observe, |
|
29 | default, observe, | |
30 | ) |
|
30 | ) | |
31 | from IPython.utils.py3compat import ( |
|
31 | from IPython.utils.py3compat import ( | |
32 |
with_metaclass, |
|
32 | with_metaclass, unicode_type, | |
33 | ) |
|
33 | ) | |
34 |
|
34 | |||
35 |
|
35 | |||
@@ -276,7 +276,7 b' class BaseFormatter(Configurable):' | |||||
276 | """ |
|
276 | """ | |
277 |
|
277 | |||
278 | format_type = Unicode('text/plain') |
|
278 | format_type = Unicode('text/plain') | |
279 |
_return_type = str |
|
279 | _return_type = str | |
280 |
|
280 | |||
281 | enabled = Bool(True).tag(config=True) |
|
281 | enabled = Bool(True).tag(config=True) | |
282 |
|
282 | |||
@@ -376,7 +376,7 b' class BaseFormatter(Configurable):' | |||||
376 | ------ |
|
376 | ------ | |
377 | KeyError if the type has not been registered. |
|
377 | KeyError if the type has not been registered. | |
378 | """ |
|
378 | """ | |
379 |
if isinstance(typ, str |
|
379 | if isinstance(typ, str): | |
380 | typ_key = tuple(typ.rsplit('.',1)) |
|
380 | typ_key = tuple(typ.rsplit('.',1)) | |
381 | if typ_key not in self.deferred_printers: |
|
381 | if typ_key not in self.deferred_printers: | |
382 | # We may have it cached in the type map. We will have to |
|
382 | # We may have it cached in the type map. We will have to | |
@@ -419,7 +419,7 b' class BaseFormatter(Configurable):' | |||||
419 | this will be the previous value (to enable restoring later). |
|
419 | this will be the previous value (to enable restoring later). | |
420 | """ |
|
420 | """ | |
421 | # if string given, interpret as 'pkg.module.class_name' |
|
421 | # if string given, interpret as 'pkg.module.class_name' | |
422 |
if isinstance(typ, str |
|
422 | if isinstance(typ, str): | |
423 | type_module, type_name = typ.rsplit('.', 1) |
|
423 | type_module, type_name = typ.rsplit('.', 1) | |
424 | return self.for_type_by_name(type_module, type_name, func) |
|
424 | return self.for_type_by_name(type_module, type_name, func) | |
425 |
|
425 | |||
@@ -491,7 +491,7 b' class BaseFormatter(Configurable):' | |||||
491 | KeyError if the type is not registered and default is not specified. |
|
491 | KeyError if the type is not registered and default is not specified. | |
492 | """ |
|
492 | """ | |
493 |
|
493 | |||
494 |
if isinstance(typ, str |
|
494 | if isinstance(typ, str): | |
495 | typ_key = tuple(typ.rsplit('.',1)) |
|
495 | typ_key = tuple(typ.rsplit('.',1)) | |
496 | if typ_key not in self.deferred_printers: |
|
496 | if typ_key not in self.deferred_printers: | |
497 | # We may have it cached in the type map. We will have to |
|
497 | # We may have it cached in the type map. We will have to | |
@@ -804,7 +804,7 b' class JSONFormatter(BaseFormatter):' | |||||
804 | r, md = r |
|
804 | r, md = r | |
805 |
|
805 | |||
806 | # handle deprecated JSON-as-string form from IPython < 3 |
|
806 | # handle deprecated JSON-as-string form from IPython < 3 | |
807 |
if isinstance(r, str |
|
807 | if isinstance(r, str): | |
808 | warnings.warn("JSON expects JSONable list/dict containers, not JSON strings", |
|
808 | warnings.warn("JSON expects JSONable list/dict containers, not JSON strings", | |
809 | FormatterWarning) |
|
809 | FormatterWarning) | |
810 | r = json.loads(r) |
|
810 | r = json.loads(r) |
@@ -67,8 +67,7 b' from IPython.utils.ipstruct import Struct' | |||||
67 | from IPython.paths import get_ipython_dir |
|
67 | from IPython.paths import get_ipython_dir | |
68 | from IPython.utils.path import get_home_dir, get_py_filename, ensure_dir_exists |
|
68 | from IPython.utils.path import get_home_dir, get_py_filename, ensure_dir_exists | |
69 | from IPython.utils.process import system, getoutput |
|
69 | from IPython.utils.process import system, getoutput | |
70 |
from IPython.utils.py3compat import |
|
70 | from IPython.utils.py3compat import builtin_mod, unicode_type, with_metaclass | |
71 | with_metaclass) |
|
|||
72 | from IPython.utils.strdispatch import StrDispatch |
|
71 | from IPython.utils.strdispatch import StrDispatch | |
73 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
72 | from IPython.utils.syspathcontext import prepended_to_syspath | |
74 | from IPython.utils.text import format_screen, LSString, SList, DollarFormatter |
|
73 | from IPython.utils.text import format_screen, LSString, SList, DollarFormatter | |
@@ -1307,8 +1306,8 b' class InteractiveShell(SingletonConfigurable):' | |||||
1307 | # We need a dict of name/value pairs to do namespace updates. |
|
1306 | # We need a dict of name/value pairs to do namespace updates. | |
1308 | if isinstance(variables, dict): |
|
1307 | if isinstance(variables, dict): | |
1309 | vdict = variables |
|
1308 | vdict = variables | |
1310 |
elif isinstance(variables, |
|
1309 | elif isinstance(variables, (str, list, tuple)): | |
1311 |
if isinstance(variables, str |
|
1310 | if isinstance(variables, str): | |
1312 | vlist = variables.split() |
|
1311 | vlist = variables.split() | |
1313 | else: |
|
1312 | else: | |
1314 | vlist = variables |
|
1313 | vlist = variables | |
@@ -1651,14 +1650,14 b' class InteractiveShell(SingletonConfigurable):' | |||||
1651 | msg = "CustomTB must return list of strings, not %r" % stb |
|
1650 | msg = "CustomTB must return list of strings, not %r" % stb | |
1652 | if stb is None: |
|
1651 | if stb is None: | |
1653 | return [] |
|
1652 | return [] | |
1654 |
elif isinstance(stb, str |
|
1653 | elif isinstance(stb, str): | |
1655 | return [stb] |
|
1654 | return [stb] | |
1656 | elif not isinstance(stb, list): |
|
1655 | elif not isinstance(stb, list): | |
1657 | raise TypeError(msg) |
|
1656 | raise TypeError(msg) | |
1658 | # it's a list |
|
1657 | # it's a list | |
1659 | for line in stb: |
|
1658 | for line in stb: | |
1660 | # check every element |
|
1659 | # check every element | |
1661 |
if not isinstance(line, str |
|
1660 | if not isinstance(line, str): | |
1662 | raise TypeError(msg) |
|
1661 | raise TypeError(msg) | |
1663 | return stb |
|
1662 | return stb | |
1664 |
|
1663 | |||
@@ -2154,7 +2153,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
2154 |
|
2153 | |||
2155 | from IPython.core import macro |
|
2154 | from IPython.core import macro | |
2156 |
|
2155 | |||
2157 |
if isinstance(themacro, str |
|
2156 | if isinstance(themacro, str): | |
2158 | themacro = macro.Macro(themacro) |
|
2157 | themacro = macro.Macro(themacro) | |
2159 | if not isinstance(themacro, macro.Macro): |
|
2158 | if not isinstance(themacro, macro.Macro): | |
2160 | raise ValueError('A macro must be a string or a Macro instance.') |
|
2159 | raise ValueError('A macro must be a string or a Macro instance.') | |
@@ -3165,7 +3164,7 b' class InteractiveShell(SingletonConfigurable):' | |||||
3165 | raise ValueError(("'%s' was not found in history, as a file, url, " |
|
3164 | raise ValueError(("'%s' was not found in history, as a file, url, " | |
3166 | "nor in the user namespace.") % target) |
|
3165 | "nor in the user namespace.") % target) | |
3167 |
|
3166 | |||
3168 |
if isinstance(codeobj, str |
|
3167 | if isinstance(codeobj, str): | |
3169 | return codeobj |
|
3168 | return codeobj | |
3170 | elif isinstance(codeobj, Macro): |
|
3169 | elif isinstance(codeobj, Macro): | |
3171 | return codeobj.value |
|
3170 | return codeobj.value |
@@ -52,6 +52,6 b' class Macro(object):' | |||||
52 | def __add__(self, other): |
|
52 | def __add__(self, other): | |
53 | if isinstance(other, Macro): |
|
53 | if isinstance(other, Macro): | |
54 | return Macro(self.value + other.value) |
|
54 | return Macro(self.value + other.value) | |
55 |
elif isinstance(other, |
|
55 | elif isinstance(other, str): | |
56 | return Macro(self.value + other) |
|
56 | return Macro(self.value + other) | |
57 | raise TypeError |
|
57 | raise TypeError |
@@ -24,7 +24,6 b' from IPython.core.inputsplitter import ESC_MAGIC, ESC_MAGIC2' | |||||
24 | from decorator import decorator |
|
24 | from decorator import decorator | |
25 | from IPython.utils.ipstruct import Struct |
|
25 | from IPython.utils.ipstruct import Struct | |
26 | from IPython.utils.process import arg_split |
|
26 | from IPython.utils.process import arg_split | |
27 | from IPython.utils.py3compat import string_types |
|
|||
28 | from IPython.utils.text import dedent |
|
27 | from IPython.utils.text import dedent | |
29 | from traitlets import Bool, Dict, Instance, observe |
|
28 | from traitlets import Bool, Dict, Instance, observe | |
30 | from logging import error |
|
29 | from logging import error | |
@@ -192,7 +191,7 b' def _method_magic_marker(magic_kind):' | |||||
192 | name = func.__name__ |
|
191 | name = func.__name__ | |
193 | retval = decorator(call, func) |
|
192 | retval = decorator(call, func) | |
194 | record_magic(magics, magic_kind, name, name) |
|
193 | record_magic(magics, magic_kind, name, name) | |
195 |
elif isinstance(arg, str |
|
194 | elif isinstance(arg, str): | |
196 | # Decorator called with arguments (@foo('bar')) |
|
195 | # Decorator called with arguments (@foo('bar')) | |
197 | name = arg |
|
196 | name = arg | |
198 | def mark(func, *a, **kw): |
|
197 | def mark(func, *a, **kw): | |
@@ -237,7 +236,7 b' def _function_magic_marker(magic_kind):' | |||||
237 | name = func.__name__ |
|
236 | name = func.__name__ | |
238 | ip.register_magic_function(func, magic_kind, name) |
|
237 | ip.register_magic_function(func, magic_kind, name) | |
239 | retval = decorator(call, func) |
|
238 | retval = decorator(call, func) | |
240 |
elif isinstance(arg, str |
|
239 | elif isinstance(arg, str): | |
241 | # Decorator called with arguments (@foo('bar')) |
|
240 | # Decorator called with arguments (@foo('bar')) | |
242 | name = arg |
|
241 | name = arg | |
243 | def mark(func, *a, **kw): |
|
242 | def mark(func, *a, **kw): | |
@@ -511,7 +510,7 b' class Magics(Configurable):' | |||||
511 | tab = self.magics[mtype] = {} |
|
510 | tab = self.magics[mtype] = {} | |
512 | cls_tab = class_magics[mtype] |
|
511 | cls_tab = class_magics[mtype] | |
513 | for magic_name, meth_name in cls_tab.items(): |
|
512 | for magic_name, meth_name in cls_tab.items(): | |
514 |
if isinstance(meth_name, str |
|
513 | if isinstance(meth_name, str): | |
515 | # it's a method name, grab it |
|
514 | # it's a method name, grab it | |
516 | tab[magic_name] = getattr(self, meth_name) |
|
515 | tab[magic_name] = getattr(self, meth_name) | |
517 | else: |
|
516 | else: |
@@ -28,7 +28,6 b' from IPython.core.magic import Magics, magics_class, line_magic' | |||||
28 | from IPython.core.oinspect import find_file, find_source_lines |
|
28 | from IPython.core.oinspect import find_file, find_source_lines | |
29 | from IPython.testing.skipdoctest import skip_doctest |
|
29 | from IPython.testing.skipdoctest import skip_doctest | |
30 | from IPython.utils import py3compat |
|
30 | from IPython.utils import py3compat | |
31 | from IPython.utils.py3compat import string_types |
|
|||
32 | from IPython.utils.contexts import preserve_keys |
|
31 | from IPython.utils.contexts import preserve_keys | |
33 | from IPython.utils.path import get_py_filename |
|
32 | from IPython.utils.path import get_py_filename | |
34 | from warnings import warn |
|
33 | from warnings import warn | |
@@ -443,7 +442,7 b' class CodeMagics(Magics):' | |||||
443 |
|
442 | |||
444 | #print '*** args',args,'type',type(args) # dbg |
|
443 | #print '*** args',args,'type',type(args) # dbg | |
445 | data = eval(args, shell.user_ns) |
|
444 | data = eval(args, shell.user_ns) | |
446 |
if not isinstance(data, str |
|
445 | if not isinstance(data, str): | |
447 | raise DataIsObject |
|
446 | raise DataIsObject | |
448 |
|
447 | |||
449 | except (NameError,SyntaxError): |
|
448 | except (NameError,SyntaxError): |
@@ -39,7 +39,7 b' from IPython.utils.path import compress_user' | |||||
39 | from IPython.utils.text import indent |
|
39 | from IPython.utils.text import indent | |
40 | from IPython.utils.wildcard import list_namespace |
|
40 | from IPython.utils.wildcard import list_namespace | |
41 | from IPython.utils.coloransi import TermColors, ColorScheme, ColorSchemeTable |
|
41 | from IPython.utils.coloransi import TermColors, ColorScheme, ColorSchemeTable | |
42 |
from IPython.utils.py3compat import cast_unicode, |
|
42 | from IPython.utils.py3compat import cast_unicode, PY3 | |
43 | from IPython.utils.colorable import Colorable |
|
43 | from IPython.utils.colorable import Colorable | |
44 |
|
44 | |||
45 | from pygments import highlight |
|
45 | from pygments import highlight | |
@@ -127,7 +127,7 b' def getdoc(obj):' | |||||
127 | pass |
|
127 | pass | |
128 | else: |
|
128 | else: | |
129 | # if we get extra info, we add it to the normal docstring. |
|
129 | # if we get extra info, we add it to the normal docstring. | |
130 |
if isinstance(ds, str |
|
130 | if isinstance(ds, str): | |
131 | return inspect.cleandoc(ds) |
|
131 | return inspect.cleandoc(ds) | |
132 | try: |
|
132 | try: | |
133 | docstr = inspect.getdoc(obj) |
|
133 | docstr = inspect.getdoc(obj) |
@@ -217,7 +217,7 b' def select_figure_formats(shell, formats, **kwargs):' | |||||
217 | jpg_formatter = shell.display_formatter.formatters['image/jpeg'] |
|
217 | jpg_formatter = shell.display_formatter.formatters['image/jpeg'] | |
218 | pdf_formatter = shell.display_formatter.formatters['application/pdf'] |
|
218 | pdf_formatter = shell.display_formatter.formatters['application/pdf'] | |
219 |
|
219 | |||
220 |
if isinstance(formats, |
|
220 | if isinstance(formats, str): | |
221 | formats = {formats} |
|
221 | formats = {formats} | |
222 | # cast in case of list / tuple |
|
222 | # cast in case of list / tuple | |
223 | formats = set(formats) |
|
223 | formats = set(formats) |
@@ -18,7 +18,7 b' from IPython.core import completer' | |||||
18 | from IPython.external.decorators import knownfailureif |
|
18 | from IPython.external.decorators import knownfailureif | |
19 | from IPython.utils.tempdir import TemporaryDirectory, TemporaryWorkingDirectory |
|
19 | from IPython.utils.tempdir import TemporaryDirectory, TemporaryWorkingDirectory | |
20 | from IPython.utils.generics import complete_object |
|
20 | from IPython.utils.generics import complete_object | |
21 |
from IPython.utils.py3compat import |
|
21 | from IPython.utils.py3compat import unicode_type | |
22 | from IPython.testing import decorators as dec |
|
22 | from IPython.testing import decorators as dec | |
23 |
|
23 | |||
24 | #----------------------------------------------------------------------------- |
|
24 | #----------------------------------------------------------------------------- | |
@@ -129,7 +129,7 b' def test_unicode_completions():' | |||||
129 | # should be thrown and the return value should be a pair of text, list |
|
129 | # should be thrown and the return value should be a pair of text, list | |
130 | # values. |
|
130 | # values. | |
131 | text, matches = ip.complete(t) |
|
131 | text, matches = ip.complete(t) | |
132 |
nt.assert_true(isinstance(text, str |
|
132 | nt.assert_true(isinstance(text, str)) | |
133 | nt.assert_true(isinstance(matches, list)) |
|
133 | nt.assert_true(isinstance(matches, list)) | |
134 |
|
134 | |||
135 | def test_latex_completions(): |
|
135 | def test_latex_completions(): |
@@ -157,6 +157,6 b' def test_bad_module_all():' | |||||
157 | results = module_completion('from bad_all import ') |
|
157 | results = module_completion('from bad_all import ') | |
158 | nt.assert_in('puppies', results) |
|
158 | nt.assert_in('puppies', results) | |
159 | for r in results: |
|
159 | for r in results: | |
160 |
nt.assert_is_instance(r, |
|
160 | nt.assert_is_instance(r, str) | |
161 | finally: |
|
161 | finally: | |
162 | sys.path.remove(testsdir) |
|
162 | sys.path.remove(testsdir) |
@@ -15,7 +15,7 b' from IPython.core.inputtransformer import InputTransformer' | |||||
15 | from IPython.core.tests.test_inputtransformer import syntax, syntax_ml |
|
15 | from IPython.core.tests.test_inputtransformer import syntax, syntax_ml | |
16 | from IPython.testing import tools as tt |
|
16 | from IPython.testing import tools as tt | |
17 | from IPython.utils import py3compat |
|
17 | from IPython.utils import py3compat | |
18 |
from IPython.utils.py3compat import |
|
18 | from IPython.utils.py3compat import input | |
19 |
|
19 | |||
20 | #----------------------------------------------------------------------------- |
|
20 | #----------------------------------------------------------------------------- | |
21 | # Semi-complete examples (also used as tests) |
|
21 | # Semi-complete examples (also used as tests) | |
@@ -100,7 +100,7 b' def test_remove_comments():' | |||||
100 |
|
100 | |||
101 | def test_get_input_encoding(): |
|
101 | def test_get_input_encoding(): | |
102 | encoding = isp.get_input_encoding() |
|
102 | encoding = isp.get_input_encoding() | |
103 |
nt.assert_true(isinstance(encoding, str |
|
103 | nt.assert_true(isinstance(encoding, str)) | |
104 | # simple-minded check that at least encoding a simple string works with the |
|
104 | # simple-minded check that at least encoding a simple string works with the | |
105 | # encoding we got. |
|
105 | # encoding we got. | |
106 | nt.assert_equal(u'test'.encode(encoding), b'test') |
|
106 | nt.assert_equal(u'test'.encode(encoding), b'test') |
@@ -1060,7 +1060,7 b' class VerboseTB(TBTools):' | |||||
1060 |
|
1060 | |||
1061 | if (not py3compat.PY3) and type(evalue) is types.InstanceType: |
|
1061 | if (not py3compat.PY3) and type(evalue) is types.InstanceType: | |
1062 | try: |
|
1062 | try: | |
1063 |
names = [w for w in dir(evalue) if isinstance(w, |
|
1063 | names = [w for w in dir(evalue) if isinstance(w, str)] | |
1064 | except: |
|
1064 | except: | |
1065 | # Every now and then, an object with funny internals blows up |
|
1065 | # Every now and then, an object with funny internals blows up | |
1066 | # when dir() is called on it. We do the best we can to report |
|
1066 | # when dir() is called on it. We do the best we can to report | |
@@ -1429,7 +1429,7 b' class SyntaxTB(ListTB):' | |||||
1429 | # be wrong (retrieved from an outdated cache). This replaces it with |
|
1429 | # be wrong (retrieved from an outdated cache). This replaces it with | |
1430 | # the current value. |
|
1430 | # the current value. | |
1431 | if isinstance(value, SyntaxError) \ |
|
1431 | if isinstance(value, SyntaxError) \ | |
1432 |
and isinstance(value.filename, |
|
1432 | and isinstance(value.filename, str) \ | |
1433 | and isinstance(value.lineno, int): |
|
1433 | and isinstance(value.lineno, int): | |
1434 | linecache.checkcache(value.filename) |
|
1434 | linecache.checkcache(value.filename) | |
1435 | newtext = ulinecache.getline(value.filename, value.lineno) |
|
1435 | newtext = ulinecache.getline(value.filename, value.lineno) |
@@ -18,7 +18,6 b' import inspect, os, sys, textwrap' | |||||
18 | from IPython.core.error import UsageError |
|
18 | from IPython.core.error import UsageError | |
19 | from IPython.core.magic import Magics, magics_class, line_magic |
|
19 | from IPython.core.magic import Magics, magics_class, line_magic | |
20 | from traitlets import Bool |
|
20 | from traitlets import Bool | |
21 | from IPython.utils.py3compat import string_types |
|
|||
22 |
|
21 | |||
23 |
|
22 | |||
24 | def restore_aliases(ip): |
|
23 | def restore_aliases(ip): | |
@@ -178,7 +177,7 b' class StoreMagics(Magics):' | |||||
178 | obj.__class__.__name__, fnam)) |
|
177 | obj.__class__.__name__, fnam)) | |
179 |
|
178 | |||
180 |
|
179 | |||
181 |
if not isinstance (obj, str |
|
180 | if not isinstance (obj, str): | |
182 | from pprint import pprint |
|
181 | from pprint import pprint | |
183 | pprint(obj, fil) |
|
182 | pprint(obj, fil) | |
184 | else: |
|
183 | else: |
@@ -36,7 +36,6 b' import threading' | |||||
36 | from IPython import get_ipython |
|
36 | from IPython import get_ipython | |
37 | from IPython.core.ultratb import AutoFormattedTB |
|
37 | from IPython.core.ultratb import AutoFormattedTB | |
38 | from logging import error |
|
38 | from logging import error | |
39 | from IPython.utils.py3compat import string_types |
|
|||
40 |
|
39 | |||
41 |
|
40 | |||
42 | class BackgroundJobManager(object): |
|
41 | class BackgroundJobManager(object): | |
@@ -171,7 +170,7 b' class BackgroundJobManager(object):' | |||||
171 | if callable(func_or_exp): |
|
170 | if callable(func_or_exp): | |
172 | kw = kwargs.get('kw',{}) |
|
171 | kw = kwargs.get('kw',{}) | |
173 | job = BackgroundJobFunc(func_or_exp,*args,**kw) |
|
172 | job = BackgroundJobFunc(func_or_exp,*args,**kw) | |
174 |
elif isinstance(func_or_exp, str |
|
173 | elif isinstance(func_or_exp, str): | |
175 | if not args: |
|
174 | if not args: | |
176 | frame = sys._getframe(1) |
|
175 | frame = sys._getframe(1) | |
177 | glob, loc = frame.f_globals, frame.f_locals |
|
176 | glob, loc = frame.f_globals, frame.f_locals |
@@ -84,7 +84,7 b' import re' | |||||
84 | import datetime |
|
84 | import datetime | |
85 | from collections import deque |
|
85 | from collections import deque | |
86 |
|
86 | |||
87 |
from IPython.utils.py3compat import PY3, PYPY, cast_unicode |
|
87 | from IPython.utils.py3compat import PY3, PYPY, cast_unicode | |
88 | from IPython.utils.encoding import get_stream_enc |
|
88 | from IPython.utils.encoding import get_stream_enc | |
89 |
|
89 | |||
90 | from io import StringIO |
|
90 | from io import StringIO | |
@@ -679,13 +679,13 b' def _type_pprint(obj, p, cycle):' | |||||
679 | mod = _safe_getattr(obj, '__module__', None) |
|
679 | mod = _safe_getattr(obj, '__module__', None) | |
680 | try: |
|
680 | try: | |
681 | name = obj.__qualname__ |
|
681 | name = obj.__qualname__ | |
682 |
if not isinstance(name, str |
|
682 | if not isinstance(name, str): | |
683 | # This can happen if the type implements __qualname__ as a property |
|
683 | # This can happen if the type implements __qualname__ as a property | |
684 | # or other descriptor in Python 2. |
|
684 | # or other descriptor in Python 2. | |
685 | raise Exception("Try __name__") |
|
685 | raise Exception("Try __name__") | |
686 | except Exception: |
|
686 | except Exception: | |
687 | name = obj.__name__ |
|
687 | name = obj.__name__ | |
688 |
if not isinstance(name, str |
|
688 | if not isinstance(name, str): | |
689 | name = '<unknown type>' |
|
689 | name = '<unknown type>' | |
690 |
|
690 | |||
691 | if mod in (None, '__builtin__', 'builtins', 'exceptions'): |
|
691 | if mod in (None, '__builtin__', 'builtins', 'exceptions'): |
@@ -7,7 +7,7 b' from warnings import warn' | |||||
7 |
|
7 | |||
8 | from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC |
|
8 | from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC | |
9 | from IPython.utils import io |
|
9 | from IPython.utils import io | |
10 |
from IPython.utils.py3compat import PY3, cast_unicode_py2, input |
|
10 | from IPython.utils.py3compat import PY3, cast_unicode_py2, input | |
11 | from IPython.utils.terminal import toggle_set_term_title, set_term_title |
|
11 | from IPython.utils.terminal import toggle_set_term_title, set_term_title | |
12 | from IPython.utils.process import abbrev_cwd |
|
12 | from IPython.utils.process import abbrev_cwd | |
13 | from traitlets import Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union |
|
13 | from traitlets import Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union | |
@@ -289,7 +289,7 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
289 | else : |
|
289 | else : | |
290 | raise ValueError('Got unknown colors: ', legacy) |
|
290 | raise ValueError('Got unknown colors: ', legacy) | |
291 | else : |
|
291 | else : | |
292 |
if isinstance(name_or_cls, str |
|
292 | if isinstance(name_or_cls, str): | |
293 | style_cls = get_style_by_name(name_or_cls) |
|
293 | style_cls = get_style_by_name(name_or_cls) | |
294 | else: |
|
294 | else: | |
295 | style_cls = name_or_cls |
|
295 | style_cls = name_or_cls |
@@ -72,7 +72,7 b' class TerminalMagics(Magics):' | |||||
72 | # Sanity checks |
|
72 | # Sanity checks | |
73 | if b is None: |
|
73 | if b is None: | |
74 | raise UsageError('No previous pasted block available') |
|
74 | raise UsageError('No previous pasted block available') | |
75 |
if not isinstance(b, |
|
75 | if not isinstance(b, str): | |
76 | raise UsageError( |
|
76 | raise UsageError( | |
77 | "Variable 'pasted_block' is not a string, can't execute") |
|
77 | "Variable 'pasted_block' is not a string, can't execute") | |
78 |
|
78 |
@@ -49,7 +49,7 b' from .ipunittest import ipdoctest, ipdocstring' | |||||
49 | from IPython.external.decorators import * |
|
49 | from IPython.external.decorators import * | |
50 |
|
50 | |||
51 | # For onlyif_cmd_exists decorator |
|
51 | # For onlyif_cmd_exists decorator | |
52 |
from IPython.utils.py3compat import |
|
52 | from IPython.utils.py3compat import which, PY2, PY3, PYPY | |
53 |
|
53 | |||
54 | #----------------------------------------------------------------------------- |
|
54 | #----------------------------------------------------------------------------- | |
55 | # Classes and functions |
|
55 | # Classes and functions | |
@@ -131,7 +131,7 b' def make_label_dec(label, ds=None):' | |||||
131 |
|
131 | |||
132 | warnings.warn("The function `make_label_dec` is deprecated since IPython 4.0", |
|
132 | warnings.warn("The function `make_label_dec` is deprecated since IPython 4.0", | |
133 | DeprecationWarning, stacklevel=2) |
|
133 | DeprecationWarning, stacklevel=2) | |
134 |
if isinstance(label, str |
|
134 | if isinstance(label, str): | |
135 | labels = [label] |
|
135 | labels = [label] | |
136 | else: |
|
136 | else: | |
137 | labels = label |
|
137 | labels = label |
@@ -354,7 +354,7 b' class AssertPrints(object):' | |||||
354 | """ |
|
354 | """ | |
355 | def __init__(self, s, channel='stdout', suppress=True): |
|
355 | def __init__(self, s, channel='stdout', suppress=True): | |
356 | self.s = s |
|
356 | self.s = s | |
357 |
if isinstance(self.s, ( |
|
357 | if isinstance(self.s, (str, _re_type)): | |
358 | self.s = [self.s] |
|
358 | self.s = [self.s] | |
359 | self.channel = channel |
|
359 | self.channel = channel | |
360 | self.suppress = suppress |
|
360 | self.suppress = suppress |
@@ -71,7 +71,7 b' def process_handler(cmd, callback, stderr=subprocess.PIPE):' | |||||
71 | # On win32, close_fds can't be true when using pipes for stdin/out/err |
|
71 | # On win32, close_fds can't be true when using pipes for stdin/out/err | |
72 | close_fds = sys.platform != 'win32' |
|
72 | close_fds = sys.platform != 'win32' | |
73 | # Determine if cmd should be run with system shell. |
|
73 | # Determine if cmd should be run with system shell. | |
74 |
shell = isinstance(cmd, |
|
74 | shell = isinstance(cmd, str) | |
75 | # On POSIX systems run shell commands with user-preferred shell. |
|
75 | # On POSIX systems run shell commands with user-preferred shell. | |
76 | executable = None |
|
76 | executable = None | |
77 | if shell and os.name == 'posix' and 'SHELL' in os.environ: |
|
77 | if shell and os.name == 'posix' and 'SHELL' in os.environ: |
@@ -6,7 +6,6 b'' | |||||
6 | # Distributed under the terms of the Modified BSD License. |
|
6 | # Distributed under the terms of the Modified BSD License. | |
7 |
|
7 | |||
8 | import inspect |
|
8 | import inspect | |
9 | from .py3compat import string_types |
|
|||
10 |
|
9 | |||
11 |
|
10 | |||
12 | def safe_hasattr(obj, attr): |
|
11 | def safe_hasattr(obj, attr): | |
@@ -44,7 +43,7 b' def dir2(obj):' | |||||
44 | # filter out non-string attributes which may be stuffed by dir() calls |
|
43 | # filter out non-string attributes which may be stuffed by dir() calls | |
45 | # and poor coding in third-party modules |
|
44 | # and poor coding in third-party modules | |
46 |
|
45 | |||
47 |
words = [w for w in words if isinstance(w, str |
|
46 | words = [w for w in words if isinstance(w, str)] | |
48 | return sorted(words) |
|
47 | return sorted(words) | |
49 |
|
48 | |||
50 |
|
49 |
@@ -17,7 +17,7 b' from warnings import warn' | |||||
17 |
|
17 | |||
18 | from IPython.utils.decorators import undoc |
|
18 | from IPython.utils.decorators import undoc | |
19 | from .capture import CapturedIO, capture_output |
|
19 | from .capture import CapturedIO, capture_output | |
20 |
from .py3compat import |
|
20 | from .py3compat import input, PY3 | |
21 |
|
21 | |||
22 | @undoc |
|
22 | @undoc | |
23 | class IOStream: |
|
23 | class IOStream: | |
@@ -63,7 +63,7 b' class IOStream:' | |||||
63 | def writelines(self, lines): |
|
63 | def writelines(self, lines): | |
64 | warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead', |
|
64 | warn('IOStream is deprecated since IPython 5.0, use sys.{stdin,stdout,stderr} instead', | |
65 | DeprecationWarning, stacklevel=2) |
|
65 | DeprecationWarning, stacklevel=2) | |
66 |
if isinstance(lines, str |
|
66 | if isinstance(lines, str): | |
67 | lines = [lines] |
|
67 | lines = [lines] | |
68 | for line in lines: |
|
68 | for line in lines: | |
69 | self.write(line) |
|
69 | self.write(line) |
@@ -154,7 +154,7 b' def filefind(filename, path_dirs=None):' | |||||
154 |
|
154 | |||
155 | if path_dirs is None: |
|
155 | if path_dirs is None: | |
156 | path_dirs = ("",) |
|
156 | path_dirs = ("",) | |
157 |
elif isinstance(path_dirs, |
|
157 | elif isinstance(path_dirs, str): | |
158 | path_dirs = (path_dirs,) |
|
158 | path_dirs = (path_dirs,) | |
159 |
|
159 | |||
160 | for path in path_dirs: |
|
160 | for path in path_dirs: |
@@ -159,7 +159,7 b' class SList(list):' | |||||
159 | except IndexError: |
|
159 | except IndexError: | |
160 | return "" |
|
160 | return "" | |
161 |
|
161 | |||
162 |
if isinstance(pattern, |
|
162 | if isinstance(pattern, str): | |
163 | pred = lambda x : re.search(pattern, x, re.IGNORECASE) |
|
163 | pred = lambda x : re.search(pattern, x, re.IGNORECASE) | |
164 | else: |
|
164 | else: | |
165 | pred = pattern |
|
165 | pred = pattern | |
@@ -307,8 +307,10 b' def list_strings(arg):' | |||||
307 | Out[9]: ['A', 'list', 'of', 'strings'] |
|
307 | Out[9]: ['A', 'list', 'of', 'strings'] | |
308 | """ |
|
308 | """ | |
309 |
|
309 | |||
310 |
if isinstance(arg, |
|
310 | if isinstance(arg, str): | |
311 |
|
|
311 | return [arg] | |
|
312 | else: | |||
|
313 | return arg | |||
312 |
|
314 | |||
313 |
|
315 | |||
314 | def marquee(txt='',width=78,mark='*'): |
|
316 | def marquee(txt='',width=78,mark='*'): |
General Comments 0
You need to be logged in to leave comments.
Login now