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