Workbench Python bugs (Python 3 release)

Expected behavior

Scripts should work in the Script Editor pane!

Actual behavior

A number of faults:

  • “Syntax error: unexpected indent”, at arbitrary places inside indented blocks of code (which works fine in Mantid Plot Python 3, etc) and after having executed some of the code before that point (such syntax errors are normally thrown only on starting to run a script). Often can be made to work by deleting extra blank lines.
  • Variables persist in a script from one run to the next. So it’s possible to have a script which does something different on the second run, or which (after careless editing, deleting the initialisation of some variable) will run in the window now but not if saved and reloaded later
  • On saving a freshly typed in script, it double spaces itself in the window! (Except the standard set of import statements at the top)
  • Tabs are still being converted to spaces in string literals.

Steps to reproduce the behavior

The following script can be tried: delete the default include statements (which aren’t relevant) and paste it in.

print ("already defined:",dir())
    print ("need to define my own UndefinedFunction4")
    def UndefinedFunction4(a=0.0):
        return a*2

To trigger the Syntax Error, insert a blank line after the “except” statement.

For the tab/space bug:

spaces="        " # some spaces
tabs="			" # some tabs (paste in)
print ("spaces", list(ord(x) for x in spaces))
print ("tabs", list(ord(x) for x in tabs))

Platforms affected

Nightly Mantid Workbench with Python 3 (Mantid 4.2.20200127.2045) on Windows

Hi James,

Thanks for pointing out these problems. I’m not sure how specific to Python 3 they are. I believe we have an issue open for each of them:
1 Unexpected Indent: #27713
2 Persistent Variables: #27185
3 Double spacing: #27558
4 Tabs to Spaces: #27557

On point 3, I haven’t myself seen a new script double space within the editor upon saving.
I will add some info to the above issues relevant to your suggestions.

Thanks. For point 2 (persistent variables) the issue seems to have been closed with two copies of it each marked as a duplicate of the other, and without an obvious pull request or actual bug fix. Does it need to be reopened?
Double spacing works for me every time. Just do “+ (new tab)”, then type (don’t paste) several lines of single spaced code below the default import statements, then “Save Script As”. Watch!

The issue for point 2: at the time, myself and Phil from the Mantid team both made raised the issue from your forum post. It is bad for us to have duplicates, so the duplicate issue was closed, but one is still open (#27185 is still marked as open at the top) as it hasn’t been worked on yet.

I can now see it double space in the script editor. Surprisingly, the way I was doing it was saving the file by pressing Ctrl+S, also brings up the Save As Dialog (as does selecting “Save Script As” in the File drop-down menu, BUT my way doesn’t double space the script in the editor. The saved out file however IS still double spaced when its reloaded back in.

@jameslord We have tracked down the double spacing issue on saving, it was an awkward newline “correction” that a module in python was doing for us behind the scenes, and the default for that was a very poor choice for windows, leading to the double spacing.

That has now been fixed, and nightly build from Tomorrow and the release of version 5.0 will include this fix.

I’m also working on a fix to resolve the unexpected indent and tabs to spaces issues as well, but that might take a few more days., but I’m confident that it will make the code freeze for release 5.0 as well.

Nick Draper