Skip to content

Add support for newer versions of Python #4

@stagg54

Description

@stagg54

I just tried this with Python 3.14 The documentation clearly says it only supports up to 3.10.

I hate to do this, but I asked Claude and it came up with a fix that seems to work.

Here is the output. I just replaced the current for loop starting on line 203 with this for loop and it seems to work.

Looking at the source code, I can see the exact problem. In _Instrument.init, the exec(_funExecStr) call creates the _FunctionXxx class inside the method's local scope, but then exec(_execString) tries to reference it — and it's not visible there.
This is a Python 3.12+ scoping change where exec() inside a method can no longer "see" names created by a previous exec() in the same scope.
The fix is to use an explicit local dict and pass it between both exec() calls:

pythonclass _Instrument:
    def __init__(self, _instrumentName, _functionClusters):
        self.name = _instrumentName

        for _functionCluster in _functionClusters:
            _functionName = _functionCluster[0]
            _functionArgList = _functionCluster[1]
            _functionDoc = _functionCluster[2]
            _funExecStr = _scriptFuncClass(_functionName, _functionArgList, _functionDoc)
            
            _local_ns = {}                          # <-- shared namespace
            exec(_funExecStr, globals(), _local_ns) # <-- define class into it
            
            _execString = (
                'self.' + _functionName +
                ' = _Function' + _functionName +
                "('" + _instrumentName + '.' + _functionName + "'," +
                repr(_functionArgList) + ')'
            )
            _local_ns['self'] = self                # <-- make self available
            exec(_execString, globals(), _local_ns) # <-- reference class from same ns

To apply the fix:
Since labview.py is inside your venv's site-packages, you can edit it directly:
C:\Users\SAS\Desktop\pybridge\venv\Lib\site-packages\jki_python_bridge_for_labview\labview.py
Find the _Instrument.init method (around line 207) and replace those four lines inside the for loop with the version above.
Why this broke in newer Python: Python 3.12 tightened exec() scoping — classes/names defined by one exec() call are no longer implicitly visible to a subsequent exec() in the same function. The JKI bridge was written for Python 3.6–3.10 (stated in the file header) and never accounted for this. Passing an explicit shared _local_ns dict to both calls is the correct fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions