Message11440
Digging a little deeper, the reason the module attribute is set to '' instead of null (in Java) is in `dottedNameListToString`. So let's try this change:
diff -r d5af3b203d59 src/org/python/antlr/PythonTree.java
--- a/src/org/python/antlr/PythonTree.java Mon Jun 12 22:31:52 2017 -0600
+++ b/src/org/python/antlr/PythonTree.java Wed Jun 14 10:36:25 2017 -0600
@@ -177,7 +177,7 @@
*/
public static String dottedNameListToString(List<Name> names) {
if (names == null) {
- return "";
+ return null;
}
StringBuilder sb = new StringBuilder();
boolean leadingDot = true;
While this diff does fix the earlier AST parsing problem so it complies with CPython's semantics, unfortunately this small change currently does not work for Jython itself, because imp.java directly builds up module names through direct appends with StringBuilder. Let's look at that specific API:
https://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html#append(java.lang.String)
>>> "If str is null, then the four characters "null" are appended."
Well this is a rather unfortunate coercion!* And it can be quicky seen in running the regrtest, so we get immediate exceptions in unittest itself, namely `ImportError: No module named unittest.null`.
Given how convoluted the import code is, I don't see us making this change until 2.7.2 unfortunately. But a small patch may prove me wrong; it should be safe for Jython given how much imports of various kinds are exercised through the standard library and testing specifically.
*At least the equivalent of `StringBuilder` in Python, `StringIO`, will write an empty string for `None`; and better yet, `"abc" + None` results in a `TypeError`. |
|
Date |
User |
Action |
Args |
2017-06-14 17:00:35 | zyasoft | set | messageid: <1497459635.6.0.67596550938.issue2598@psf.upfronthosting.co.za> |
2017-06-14 17:00:35 | zyasoft | set | recipients:
+ zyasoft, stefan.richthofer, jenselme |
2017-06-14 17:00:35 | zyasoft | link | issue2598 messages |
2017-06-14 17:00:34 | zyasoft | create | |
|