Skip to content

Commit aae840d

Browse files
authored
Merge pull request #502 from anikamukherji/optimize-is-new-byte
remove import for isnewbytes
2 parents acaaed3 + 5cfebd1 commit aae840d

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ sudo: false
22
language: python
33
cache: pip
44

5+
56
matrix:
67
include:
78
- python: 2.6
89
env: TOXENV=py26
10+
dist: trusty
911
- python: 2.7
1012
env: TOXENV=py27
1113
- python: 3.3
1214
env: TOXENV=py33
15+
dist: trusty
16+
sudo: false
1317
- python: 3.4
1418
env: TOXENV=py34
1519
- python: 3.5

src/future/tests/base.py

+4
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ def _futurize_test_script(self, filename='mytestscript.py', stages=(1, 2),
342342
'----\n%s\n----' % f.read(),
343343
)
344344
ErrorClass = (FuturizeError if 'futurize' in script else PasteurizeError)
345+
346+
if not hasattr(e, 'output'):
347+
# The attribute CalledProcessError.output doesn't exist on Py2.6
348+
e.output = None
345349
raise ErrorClass(msg, e.returncode, e.cmd, output=e.output)
346350
return output
347351

src/future/utils/__init__.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -577,15 +577,14 @@ def isbytes(obj):
577577

578578
def isnewbytes(obj):
579579
"""
580-
Equivalent to the result of ``isinstance(obj, newbytes)`` were
581-
``__instancecheck__`` not overridden on the newbytes subclass. In
582-
other words, it is REALLY a newbytes instance, not a Py2 native str
580+
Equivalent to the result of ``type(obj) == type(newbytes)``
581+
in other words, it is REALLY a newbytes instance, not a Py2 native str
583582
object?
583+
584+
Note that this does not cover subclasses of newbytes, and it is not
585+
equivalent to ininstance(obj, newbytes)
584586
"""
585-
# TODO: generalize this so that it works with subclasses of newbytes
586-
# Import is here to avoid circular imports:
587-
from future.types.newbytes import newbytes
588-
return type(obj) == newbytes
587+
return type(obj).__name__ == 'newbytes'
589588

590589

591590
def isint(obj):

tests/test_future/test_utils.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,14 @@ def test_chained_exceptions_stacktrace(self):
379379
class CustomException(Exception):
380380
if PY2:
381381
def __str__(self):
382-
out = Exception.__str__(self)
383-
if hasattr(self, '__cause__') and self.__cause__ and hasattr(self.__cause__, '__traceback__') and self.__cause__.__traceback__:
384-
out += '\n\nThe above exception was the direct cause of the following exception:\n\n'
385-
out += ''.join(traceback.format_tb(self.__cause__.__traceback__) + ['{}: {}'.format(self.__cause__.__class__.__name__, self.__cause__)])
386-
return out
382+
try:
383+
out = Exception.__str__(self)
384+
if hasattr(self, '__cause__') and self.__cause__ and hasattr(self.__cause__, '__traceback__') and self.__cause__.__traceback__:
385+
out += '\n\nThe above exception was the direct cause of the following exception:\n\n'
386+
out += ''.join(traceback.format_tb(self.__cause__.__traceback__) + ['{0}: {1}'.format(self.__cause__.__class__.__name__, self.__cause__)])
387+
return out
388+
except Exception as e:
389+
print(e)
387390
else:
388391
pass
389392

0 commit comments

Comments
 (0)