[BUG] ScriptEditor executes Python code while editing

The Rhino Script Editor IDE unexpectedly executes Python code while editing.
If a variable is named imported_data and you type a "." (dot), the IDE executes a previously imported module

Steps to Reproduce:

  1. Create a file with the following code, e.g.:
# testrun.py
import rhinoscriptsyntax as rs

def testprint():
    line_1 = "THIS IS STRANGE"
    line_2 = "UNUSUAL"
    line_3 = "BEHAVIOR"
    message_text = line_1 + "\n" + line_2 + "\n" + line_3
    rs.MessageBox(message_text)
  1. Save this file as “testrun.py”.
  2. Create a new file and save as e.g. “test2.py”.
  3. Insert the following code:
# test2.py
import testrun
from importlib import reload
reload(testrun)

imported_data = testrun.testprint()
  1. Execute this code.
  2. Try adding a dot (.) after imported_data on a new line.

Expected Behavior:

  • Nothing, just the dot.

Actual Behavior:

  • The IDE executes the function (testrun.testprint())

Ooof great catch. I will get this fixed ASAP.

RH-86612 Python completion accidentally executes code

Yes, I was surprised. How it’s possible?

Here is a quick explanation:

Python provides autocompletion but it is inherently not a Typed programming language. So when it tries to complete for variable m for example, it needs to know what is the type of m (e.g. Brep). To detect that it normally has one option and that is static analysis. It needs to parse the code, look at the imported modules and data types defined in them, etc.

That takes time. So the script editor in Rhino, in order to be more responsive, parses the script creating a smaller version of that script with only import statements and the variable it wants to complete for, and runs that in the background to determine the runtime type of that variable. If it can not determine the type using this method, it calls the language server for static analysis (slower) but that usually provides ok results.

This is definitely a bug in that process. It is grabbing the imported_data = testrun.testprint() not realizing there is a function call in there.

RH-86612 is fixed in Rhino 8 Service Release 18 Release Candidate