GitHub user dgingrich opened a pull request:
https://github.com/apache/spark/pull/16845
[SPARK-19505][Python] AttributeError on Exception.message in Python3
## What changes were proposed in this pull request?
Switch from "e.message" to "str(e)" for Python 3 compatibility. Grepped
for all occurrences of `.message` in `pyspark/` and these were the only
occurrences.
## How was this patch tested?
- No regression of automated tests (`python/run-tests.py` passed,
`dev/run-tests` had failures when pulling from `master` and same failures
afterwards)
- Code inspection
- Manually tested the `e.message` -> `str(e)` change in the REPL:
Python 2:
```
$ python
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> e = Exception('test')
>>> str(e)
'test'
>>> e.message
'test'
```
Python 3:
```
$ python3
Python 3.4.5 (default, Sep 29 2016, 00:36:58)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> e = Exception('test')
>>> str(e)
'test'
>>> e.message
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Exception' object has no attribute 'message'
```
Open to suggestions on adding better unit tests for the failure itself.
Could do a conditional `unittest.mock` import (like for `unittest2`) and patch
the underlying calls but that seemed like overkill.
## Legal
This is my original work and that I license the work to the project under
the projectâs open source license.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/dgingrich/spark
topic-spark-19505-py3-exceptions
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/16845.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #16845
----
commit cb5c34d80b0f0551514d0153a543210ba1e7ea0e
Author: David Gingrich <[email protected]>
Date: 2017-02-08T00:14:21Z
Support Python 3 exception messages
* Switch from "e.message" to "str(e)"
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]