Message11426
So this diff fixes by providig the appropriate TypeError - we are not using the formatted string as the new message. Note that for non-native types, CPython has a slightly different message "must be convertible to a buffer, not Foo", but I don't see this as being necessary for this fix (unless easy).
$ hg diff
diff -r c558ce4072ee src/org/python/core/PyFile.java
--- a/src/org/python/core/PyFile.java Wed Jun 07 08:29:12 2017 +0100
+++ b/src/org/python/core/PyFile.java Fri Jun 09 16:10:23 2017 -0600
@@ -506,7 +506,7 @@
if (message == null) {
// Messages differ for text or binary streams (CPython) but we always add the type
- String.format("%s buffer, not %.200s", (binary ? "must be string or"
+ message = String.format("%s buffer, not %.200s", (binary ? "must be string or"
: "expected a character"), obj.getType().fastGetName());
}
throw Py.TypeError(message);
There is a somewhat similar problem in pickle/cPickle, but at least not a NPE. As we saw with Py.newStringOrUnicode, we might want to put this conversion logic in a common place:
Jython 2.7.1rc2 (default:c558ce4072ee+, Jun 9 2017, 16:10:36)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_112
Type "help", "copyright", "credits" or "license" for more information.
>>> import pickle
>>> pickle.loads(47)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jbaker/jythondev/jython27/dist/Lib/pickle.py", line 1381, in loads
file = StringIO(str)
TypeError: StringIO(): 1st arg can't be coerced to java.lang.CharSequence, org.python.core.PyArray
>>> import cPickle
>>> cPickle.loads(47)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cPickle.UnpicklingError: invalid load key, '4'.
>>>
jimbaker:jython27 jbaker$ python
Python 2.7.10 |Anaconda 2.3.0 (x86_64)| (default, May 28 2015, 17:04:42)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import pickle, cPickle
>>> pickle.loads(47)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jbaker/anaconda/lib/python2.7/pickle.py", line 1381, in loads
file = StringIO(str)
TypeError: must be string or buffer, not int
>>> cPickle.loads(47)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be string, not int
>>> |
|
Date |
User |
Action |
Args |
2017-06-09 22:17:04 | zyasoft | set | messageid: <1497046624.38.0.275787850764.issue2593@psf.upfronthosting.co.za> |
2017-06-09 22:17:04 | zyasoft | set | recipients:
+ zyasoft, fwierzbicki, jeff.allen, tkanerva |
2017-06-09 22:17:04 | zyasoft | link | issue2593 messages |
2017-06-09 22:17:02 | zyasoft | create | |
|