Repository: ipython/ipython

Issue:
AttributeError: 'StreamLogger' object has no attribute 'isatty'
OS: macOS 10.11.6
Python version: Python 2.7.10
ipython version: IPython 5.0.0

Scrapy project with settings:
`LOG_STDOUT = True`
which redirects stdout to log

```
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/scrapy/utils/defer.py", line 102, in iter_errback
    yield next(it)
  File "/Library/Python/2.7/site-packages/scrapy_splash/middleware.py", line 156, in process_spider_output
    for el in result:
  File "/Library/Python/2.7/site-packages/scrapy/spidermiddlewares/offsite.py", line 29, in process_spider_output
    for x in result:
  File "/Library/Python/2.7/site-packages/scrapy/spidermiddlewares/referer.py", line 22, in <genexpr>
    return (_set_referer(r) for r in result or ())
  File "/Library/Python/2.7/site-packages/scrapy/spidermiddlewares/urllength.py", line 37, in <genexpr>
    return (r for r in result or () if _filter(r))
  File "/Library/Python/2.7/site-packages/scrapy/spidermiddlewares/depth.py", line 58, in <genexpr>
    return (r for r in result or () if _filter(r))
  File "/Users/mini/PycharmProjects/spider_demo/spider_demo/spiders/baidu_news.py", line 42, in parse
    inspect_response(response, self)
  File "/Library/Python/2.7/site-packages/scrapy/shell.py", line 157, in inspect_response
    Shell(spider.crawler).start(response=response)
  File "/Library/Python/2.7/site-packages/scrapy/shell.py", line 80, in start
    banner=self.vars.pop('banner', ''))
  File "/Library/Python/2.7/site-packages/scrapy/utils/console.py", line 75, in start_python_console
    shell = get_shell_embed_func(shells)
  File "/Library/Python/2.7/site-packages/scrapy/utils/console.py", line 63, in get_shell_embed_func
    return known_shells[shell]()
  File "/Library/Python/2.7/site-packages/scrapy/utils/console.py", line 7, in _embed_ipython_shell
    from IPython.terminal.embed import InteractiveShellEmbed
  File "/Library/Python/2.7/site-packages/IPython/__init__.py", line 49, in <module>
    from .terminal.embed import embed
  File "/Library/Python/2.7/site-packages/IPython/terminal/embed.py", line 17, in <module>
    from IPython.terminal.interactiveshell import TerminalInteractiveShell
  File "/Library/Python/2.7/site-packages/IPython/terminal/interactiveshell.py", line 77, in <module>
    _is_tty = (sys.stdin.isatty()) and (sys.stdout.isatty()) and  (sys.stderr.isatty())
AttributeError: 'StreamLogger' object has no attribute 'isatty'
```



Discussion:

Resolving patch:
diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py
--- a/IPython/terminal/interactiveshell.py
+++ b/IPython/terminal/interactiveshell.py
@@ -74,11 +74,17 @@ def get_default_editor():
     else:
         return 'notepad' # same in Windows!
 
-
-if sys.stdin and sys.stdout and sys.stderr:
-    _is_tty = (sys.stdin.isatty()) and (sys.stdout.isatty()) and  (sys.stderr.isatty())
+# conservatively check for tty
+# overridden streams can result in things like:
+# - sys.stdin = None
+# - no isatty method
+for _name in ('stdin', 'stdout', 'stderr'):
+    _stream = getattr(sys, _name)
+    if not _stream or not hasattr(_stream, 'isatty') or not _stream.isatty():
+        _is_tty = False
+        break
 else:
-    _is_tty = False
+    _is_tty = True
 
 
 _use_simple_prompt = ('IPY_TEST_SIMPLE_PROMPT' in os.environ) or (not _is_tty)


Test patch: