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.

Python3.9 NuitkaOptimizationError with annotated generics

See original GitHub issue

I recently upgraded a project to Python 3.9 and changed the type annotations to PEP 585 style. My project compiles fine except for one nested function with annotated generics.

Versions:

  • nuitka-0.6.14.7
  • Python 3.9.4
  • ubuntu:16.04

Python installed with apt-get (deadsnakes), Nuitka installed with pip.

Run with:

nuitka3 --no-pyi-file --module featuremine_utils --include-package featuremine_utils

Minimal code to cause failure:

def f():
    def inner_f() -> list[str]:
        pass

Failure

Traceback (most recent call last):β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ                  | 133/150
  File "/usr/local/lib/python3.9/dist-packages/nuitka/__main__.py", line 185, in <module>
    main()
  File "/usr/local/lib/python3.9/dist-packages/nuitka/__main__.py", line 171, in main
    MainControl.main()
  File "/usr/local/lib/python3.9/dist-packages/nuitka/MainControl.py", line 692, in main
    main_module = _createNodeTree(filename=filename)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/MainControl.py", line 161, in _createNodeTree
    Optimization.optimize(main_module.getOutputFilename())
  File "/usr/local/lib/python3.9/dist-packages/nuitka/optimizations/Optimization.py", line 379, in optimize
    finished = makeOptimizationPass()
  File "/usr/local/lib/python3.9/dist-packages/nuitka/optimizations/Optimization.py", line 325, in makeOptimizationPass
    changed = optimizeModule(current_module)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/optimizations/Optimization.py", line 220, in optimizeModule
    changed = optimizeCompiledPythonModule(module)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/optimizations/Optimization.py", line 120, in optimizeCompiledPythonModule
    scopes_were_incomplete = module.computeModule()
  File "/usr/local/lib/python3.9/dist-packages/nuitka/nodes/ModuleNodes.py", line 530, in computeModule
    result = module_body.computeStatementsSequence(
  File "/usr/local/lib/python3.9/dist-packages/nuitka/nodes/StatementNodes.py", line 163, in computeStatementsSequence
    new_statement = statement.computeStatementsSequence(trace_collection)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/nodes/FrameNodes.py", line 182, in computeStatementsSequence
    new_statement = trace_collection.onStatement(statement=statement)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/optimizations/TraceCollections.py", line 558, in onStatement
    new_statement, change_tags, change_desc = statement.computeStatement(self)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/nodes/AssignNodes.py", line 275, in computeStatement
    source = trace_collection.onExpression(self.subnode_source)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/optimizations/TraceCollections.py", line 539, in onExpression
    r = expression.computeExpressionRaw(trace_collection=self)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/nodes/ExpressionBases.py", line 1112, in computeExpressionRaw
    expression = trace_collection.onExpression(sub_expression)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/optimizations/TraceCollections.py", line 539, in onExpression
    r = expression.computeExpressionRaw(trace_collection=self)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/nodes/FunctionNodes.py", line 1097, in computeExpressionRaw
    trace_collection.onUsedFunction(self.getFunctionBody())
  File "/usr/local/lib/python3.9/dist-packages/nuitka/optimizations/TraceCollections.py", line 435, in onUsedFunction
    function_body.computeFunctionRaw(self)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/nodes/FunctionNodes.py", line 501, in computeFunctionRaw
    self.computeFunction(trace_collection)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/nodes/FunctionNodes.py", line 516, in computeFunction
    result = statements_sequence.computeStatementsSequence(
  File "/usr/local/lib/python3.9/dist-packages/nuitka/nodes/StatementNodes.py", line 165, in computeStatementsSequence
    new_statement = trace_collection.onStatement(statement=statement)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/optimizations/TraceCollections.py", line 558, in onStatement
    new_statement, change_tags, change_desc = statement.computeStatement(self)
  File "/usr/local/lib/python3.9/dist-packages/nuitka/nodes/TryNodes.py", line 141, in computeStatement
    raise NuitkaOptimizationError(
nuitka.Errors.NuitkaOptimizationError: 
This statement does raise but didn't annotate an exception exit.

    <node kind="StatementsFrameFunction" line="41" co_name="f" co_kind="Function" co_varnames="inner_f" co_freevars="" co_argcount="0" co_posonlyargcount="0" co_kwonlyargcount="0" co_has_starlist="False" co_has_stardict="False" co_filename="featuremine_utils/common.py" co_lineno="41" co_new_locals="True" co_is_optimized="True" code_flags="">
      <role name="statements" type="list">
        <node kind="StatementAssignmentVariable" line="42" variable_name="inner_f" is_temp="False" var_type="object" owner="featuremine_utils$common$$$function__3_f">
          <role name="source">
            <node kind="ExpressionFunctionCreation" line="42">
              <role name="defaults" type="list" />
              <role name="kw_defaults" type="none" />
              <role name="annotations">
                <node kind="ExpressionMakeDict" line="42">
                  <role name="pairs" type="list">
                    <node kind="ExpressionKeyValuePair" line="42">
                      <role name="key">
                        <node kind="ExpressionConstantStrRef" line="42" constant="'return'" user_provided="True" />
                      </role>
                      <role name="value">
                        <node kind="ExpressionSubscriptLookup" line="42">
                          <role name="expression">
                            <node kind="ExpressionConstantTypeRef" line="42" constant="&lt;class 'list'&gt;" />
                          </role>
                          <role name="subscript">
                            <node kind="ExpressionConstantTypeRef" line="42" constant="&lt;class 'str'&gt;" />
                          </role>
                        </node>
                      </role>
                    </node>
                  </role>
                </node>
              </role>
              <role name="function_ref">
                <node kind="ExpressionFunctionRef" line="42" code_name="featuremine_utils$common$$$function__3_f$$$function__1_inner_f" />
              </role>
            </node>
          </role>
        </node>
      </role>
    </node>

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kayhayencommented, May 25, 2021

Part of 0.6.15 release.

0reactions
bphillips-exoscommented, May 22, 2021

Thanks for the quick response!

Unfortunately I cannot reproduce the crash

Perhaps other code in the file contributed to the exception. Happy to try and create a self-contained example if that would help.

This might be better on https://nuitka.net/doc/factory.html

Yes! The build passes with the factory version. I did test against the β€œdevelop” version yesterday before creating the ticket, but that build failed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuitka Dependancy Error - python
I'm trying to compile a simple standalone python application using Nuitka. I was able to do this using just the standard library.
Read more >
nuitka Changelog
e.g. no variable version was allocated to assignments. code volume, as it became more generic code. optimization. help portable mode.
Read more >
Release 0.23.0 Gregory Szorc
A Python extension module [implemented in Rust] providing a highly performant alternate module and resource im- porting mechanism.
Read more >
Python 3.11.0 final
Love the Variadic Generics (embed array layout into its type top avoid confusion). A surprisingly common issue in data science code. But.. I...
Read more >
beartype - Python Package Health Analysis
Beartype never emits errors, warnings, or exceptions on dynamically-typed code ... Python β‰₯ 3.9.0 # from typing_extensions import Annotated # <-- if Python...
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