question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with conditional expressions using constants non boolean values.

See original GitHub issue

Hello,

I found a code where CPython works and nuitka fails compiling.

python -m nuitka --standalone nuitka_test.py
Problem with <Node 'STATEMENT_CONDITIONAL'> at nuitka_test.py:2
Problem with <Node 'STATEMENT_TRY'> at nuitka_test.py:1
Nuitka:WARNING:Problem creating function code '__main__$$$function_1_test'.
Nuitka:WARNING:Problem creating code for module <Node 'PYTHON_MAIN_MODULE' with {'filename': 'nuitka_test.py', 'main_added': False, 'mode': 'compiled'}>.
Traceback (most recent call last):
  File "C:\Python37-32\lib\site-packages\nuitka\__main__.py", line 184, in <module>
    main()
  File "C:\Python37-32\lib\site-packages\nuitka\__main__.py", line 177, in main
    MainControl.main()
  File "C:\Python37-32\lib\site-packages\nuitka\MainControl.py", line 756, in main
    result, options = compileTree(main_module=main_module)
  File "C:\Python37-32\lib\site-packages\nuitka\MainControl.py", line 649, in compileTree
    makeSourceDirectory(main_module=main_module)
  File "C:\Python37-32\lib\site-packages\nuitka\MainControl.py", line 377, in makeSourceDirectory
    module_name=module.getFullName(),
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeGeneration.py", line 413, in prepareModuleCode
    function_body=function_body, context=context
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeGeneration.py", line 352, in generateFunctionBodyCode
    cross_module=function_body.isCrossModuleUsed()
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\FunctionCodes.py", line 535, in getFunctionCode
    needs_exception_exit=needs_exception_exit,
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\FunctionCodes.py", line 572, in _getFunctionCode
    context=context,
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 246, in generateStatementSequenceCode
    statement_sequence=statement_sequence, emit=emit, context=context
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 217, in _generateStatementSequenceCode
    statement=statement, emit=statement_codes, context=context
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 173, in generateStatementCode
    statement=statement, emit=emit, context=context
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\TryCodes.py", line 87, in generateTryCode
    statement_sequence=tried_block, emit=emit, allow_none=False, context=context
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 246, in generateStatementSequenceCode
    statement_sequence=statement_sequence, emit=emit, context=context
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 208, in _generateStatementSequenceCode
    statement_sequence=statement, emit=emit, context=context
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\FrameCodes.py", line 128, in generateStatementsFrameCode
    statement_sequence=statement_sequence, emit=local_emit, context=context
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 217, in _generateStatementSequenceCode
    statement=statement, emit=statement_codes, context=context
  File "C:\Python37-32\lib\site-packages\nuitka\codegen\CodeHelpers.py", line 177, in generateStatementCode
    assert not context.getCleanupTempnames(), context.getCleanupTempnames()
AssertionError: [<VariableDeclaration PyObject * tmp_constant_value_1 = None>]
  • Please check whether the bug was already reported or fixed. Does not seem to
  • Please check out if the develop version of Nuitka works better for you. Running pre-release already 😃

If you want to post a problem/bug, to help us understand and resolve your issue please check that you have provided at least the information below, and discard up to here:

  • Nuitka version, full Python version and Platform (Windows, OSX, Linux …) 0.6.4rc3 Python: 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] Executable: C:\Python37-32\python.exe OS: Windows Arch: x86

  • How did you install Nuitka and Python (pip, anaconda, deb, rpm, from source, what is a virtualenv …), this is very important usually. Installed from pre-release msi file on windows.

  • 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.

Smallest example I could make:

def test(somelist=None):
    if 'element' in somelist if somelist is not None else []:
        print('yes')
    else:
        print('no')

test(['some', 'element'])
test()

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kayhayencommented, May 22, 2019

Ok, turns out, that because this is roughly the only case where a constant value PyObject * used as nuitka_bool is not yet optimized properly away, this ran into code that produced the nuitka_bool from the constant object (which in case of the list, is actually created and needs a release), which then is complained about. This would have been reference leaking, which Nuitka caught itself doing.

So we see this only because it’s in a conditional expression in a conditional statement with a constant value that takes a reference.

I am going to put this through my Buildbots, then on factory for the immanent next release.

0reactions
kayhayencommented, Jun 10, 2019

Released as 0.6.4

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditional contraints in linear programming for non boolean ...
Question 2 : a , b , c , d , e are integer non negative variables if any one of above >...
Read more >
Conditionals with if/else & Booleans | AP CSP (article)
The condition is a Boolean expression: an expression that evaluates to either true or false . Boolean values are another type of data...
Read more >
Tests of non-Boolean values against zero should be explicit
Where a data value is to be tested against zero then the test should be made explicit. The exception to this rule is...
Read more >
9. Working with Booleans and Conditional Statements
A Boolean expression is an expression that evaluates to produce a result which is a Boolean value. For example, the operator == tests...
Read more >
If Statements - Happy Coding
Boolean variables wouldn't be very useful if you had to decide their values ahead of time. Instead, you can obtain boolean values through...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found