improve slice view (PY-13837) and add logic for ndarray slice evaluation
authorAlexander Marchuk <Alexander.Marchuk@jetbrains.com>
Thu, 4 Sep 2014 15:27:32 +0000 (19:27 +0400)
committerAlexander Marchuk <Alexander.Marchuk@jetbrains.com>
Thu, 4 Sep 2014 15:27:32 +0000 (19:27 +0400)
fix PY-13850 Evaluate list item for octal return SyntaxError

python/helpers/pydev/pydevd_resolver.py
python/pydevSrc/com/jetbrains/python/debugger/PyDebugValue.java

index 51d9be0f23d3a66862cdf91eda69625f3e151c7d..acb611dc4528e8188e06b363426b0d5251eb9f31 100644 (file)
@@ -439,7 +439,7 @@ class NdArrayResolver:
         ret['shape'] = obj.shape
         ret['dtype'] = obj.dtype
         ret['size'] = obj.size
-        ret['[0:%s]' % (len(obj))] = {'items' : str(obj)}
+        ret['[0:%s]' % (len(obj))] = list(obj)
         return ret
 
 class NdArrayItemsContainer: pass
index bdcf5e41a4cfa49472d2aa34e2003c120db2a95e..ddec6797ea8dcc6019b066473815ac8fa523efea 100644 (file)
@@ -97,7 +97,7 @@ public class PyDebugValue extends XNamedValue {
       myParent.buildExpression(result);
       if (("dict".equals(myParent.getType()) || "list".equals(myParent.getType()) || "tuple".equals(myParent.getType())) &&
           !isLen(myName)) {
-        result.append('[').append(removeId(myName)).append(']');
+        result.append('[').append(removeLeadingZeros(removeId(myName))).append(']');
       }
       else if (("set".equals(myParent.getType())) && !isLen(myName)) {
         //set doesn't support indexing
@@ -105,6 +105,9 @@ public class PyDebugValue extends XNamedValue {
       else if (isLen(myName)) {
         result.append('.').append(myName).append("()");
       }
+      else if (("ndarray".equals(myParent.getType()) || "matrix".equals(myParent.getType())) && myName.startsWith("[")) {
+        result.append(removeLeadingZeros(myName));
+      }
       else {
         result.append('.').append(myName);
       }
@@ -119,6 +122,11 @@ public class PyDebugValue extends XNamedValue {
     return name;
   }
 
+  private static String removeLeadingZeros(@NotNull String name) {
+    //bugs.python.org/issue15254: "0" prefix for octal
+    return name.replaceFirst("^0+(?!$)", "");
+  }
+
   private static boolean isLen(String name) {
     return "__len__".equals(name);
   }