Nuitka: `del` on local variable `setup_rt` yields `UnboundLocalError: local variable 'setup_rt' referenced before assignment`

Created on 12 May 2020  路  5Comments  路  Source: Nuitka/Nuitka

  • Nuitka version, full Python version and Platform (Windows, OSX, Linux ...)
> /opt/conda/bin/python -m nuitka --version
0.6.9rc1
Python: 3.7.4 (default, Aug 13 2019, 15:17:50)
Executable: /opt/conda/bin/python
OS: Darwin
Arch: x86_64
  • How did you install Nuitka and Python (pip, anaconda, deb, rpm, from source,
    what is a virtualenv ...), this is very important usually.

/opt/conda/bin/python -m pip install -U "https://github.com/Nuitka/Nuitka/archive/develop.zip"

  • Many times when you get an error from Nuitka, your setup may be so special
    that even a "hello world" program will not work, please try that and report
    it instead.

Hello world-style programs and more complex programs work. Commenting out the failing line - line 140 - resolves the issue as well.

  • If possible please supply a Short, Self Contained, Correct, Example
    that demonstrates the issue i.e a small piece of code which reproduces
    the issue and can be run with out any other (or as few as possible)
    external dependencies.

First install ruamel.yaml version 0.16.10 and then create the following test.py:

from ruamel.yaml import YAML

if __name__ == "__main__":
  print(YAML())

Compiled using /opt/conda/bin/python3 -m nuitka --no-pyi-file --python-flag=no_site --plugin-enable=pylint-warnings --remove-output --nofollow-imports --show-scons --standalone --clang --include-module=ruamel.yaml test.py

This yields the following output when running test.dist/test:

Traceback (most recent call last):
  File "/Users/alash/git/minimal/test.dist/test.py", line 4, in <module>
  File "/Users/alash/git/minimal/test.dist/ruamel/yaml/main.py", line 140, in __init__
UnboundLocalError: local variable 'setup_rt' referenced before assignment

The same error is yielded with:

  • /opt/conda/bin/python3 -m nuitka --follow-import-to=ruamel.yaml --follow-import-to=ruamel test.py && ./test.bin

No errors running:

  • /opt/conda/bin/python3 -m nuitka --nofollow-imports test.py && ./test.bin
  • /opt/conda/bin/python3 test.py

I tried but was unable to come up with a simpler reproduction that does not involve ruamel.yaml.

  • If this is a regression (used to work in an earlier version of Nuitka),
    please note what you know about that.

Did not work on 0.6.7 either; same error.

bug

All 5 comments

https://sourceforge.net/p/ruamel-yaml/code/ci/default/tree/main.py#l140 the failing line; it seems that setup_rt should unconditionally exist at that line.

In case it helps, I generated the c with the del and with a blank line instead, yielding the following diff:

diff -r with_del.build/module.ruamel.yaml.main.c without_del.build/module.ruamel.yaml.main.c
4843,4858d4842
<     tmp_result = var_setup_rt == NUITKA_BOOL_UNASSIGNED;
<     var_setup_rt = NUITKA_BOOL_UNASSIGNED;
<     if (tmp_result == false) {
<
<         exception_type = PyExc_UnboundLocalError;
<         Py_INCREF(exception_type);
<         exception_value = PyUnicode_FromFormat("local variable '%s' referenced before assignment", "setup_rt");
<         exception_tb = NULL;
<         NORMALIZE_EXCEPTION(&exception_type, &exception_value, &exception_tb);
<         CHAIN_EXCEPTION(exception_value);
<
<         exception_lineno = 140;
<         type_description_1 = "ooooooooobo";
<         goto frame_exception_exit_1;
<     }
<

It seems that tmp_result = var_setup_rt == NUITKA_BOOL_UNASSIGNED; should be tmp_result = var_setup_rt != NUITKA_BOOL_UNASSIGNED; - i.e. the exception should be raised iff var_setup_rt is unassigned?

That's absolutely perfect @abl and makes a fix easy I believe. Expect one later today.

This must be a recent regression, I think previously a del precluded from C boolean shape, and therefore the buggy code was dead. I pushed a fix to factory and will consider making a hotfix later today.

This is release as part of 0.6.8.1 hotfix.

Was this page helpful?
0 / 5 - 0 ratings