Skip to content

Packaging fails when using type aliases with explicit type #4007

@torablien

Description

@torablien

Duplicate Check

Describe the bug

When packaging a Flet app (e.g. via flet build macos), type aliases seem to cause build failures (but works fine when running with flet run). On smaller applications, this is flagged in verbose mode as a syntax error, but in larger applications (seemingly defined as ones with many dependencies even if no real logic), this fails opaquely.

Example error in smaller application:

Listing '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/__pypackages__/sniffio/_tests'...
Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/__pypackages__/sniffio/_tests/__init__.py'...
Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/__pypackages__/sniffio/_tests/test_sniffio.py'...
Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/__pypackages__/sniffio/_version.py'...
Listing '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/__pypackages__/sniffio-1.3.1.dist-info'...
Listing '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/assets'...
Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/main.py'...
***   File "/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_temp1QKqZ2/main.py", line 4
    type Vector = list[float]
         ^^^^^^
SyntaxError: invalid syntax
[20:24:15] Deleting Flutter bootstrap directory /var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/flet_flutter_build_Txn9fVXWcE                                                                                                                           
           Error building Flet app - see the log of failed command above.                                                                                                                                                                                
           Run subprocess: ['/Users/neil/Code/flutter/bin/flutter', 'doctor']      

Example error in larger application:

Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempWb6cOI/venv/lib/python3.12/site-packages/yaml/scanner.py'...
Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempWb6cOI/venv/lib/python3.12/site-packages/yaml/serializer.py'...
Compiling '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempWb6cOI/venv/lib/python3.12/site-packages/yaml/tokens.py'...
Listing '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempWb6cOI/venv/share'...
Listing '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempWb6cOI/venv/share/man'...
Listing '/var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/serious_python_tempWb6cOI/venv/share/man/man1'...
[20:32:35] Deleting Flutter bootstrap directory /var/folders/q1/dcc1rnq13f9fhs4hxd03jqy80000gn/T/flet_flutter_build_JsOzp4wfPt                                                                                                                           
           Error building Flet app - see the log of failed command above.                                                                                                                                                                                
           Run subprocess: ['/Users/neil/Code/flutter/bin/flutter', 'doctor']       

Code sample

Running flet build macos -vv on simple Hello World app.

Failing:

import flet as ft


type Vector = list[float]


class VectorDB:
    def __init__(self):
        self.db: dict[str, Vector] = {}


def main(page: ft.Page):
    vector_db = VectorDB()
    page.add(ft.SafeArea(ft.Text("Hello, Flet!")))


ft.app(main)

Works:

import flet as ft


class VectorDB:
    def __init__(self):
        self.db: dict[str, list[float]] = {}


def main(page: ft.Page):
    vector_db = VectorDB()
    page.add(ft.SafeArea(ft.Text("Hello, Flet!")))


ft.app(main)

Both work when running via flet run

The only difference between smaller vs larger app re the missing error logs is the amount of requirements in requirements.txt. Small app has few to no requirements where the large app has many (even though the app remains just hello world).

To reproduce

Run flet create hello_world and add a type alias declaration to main.py (or any file). Then run flet build macos -vv.

Operating System

macOS - M1 Pro

Operating system details

Sonoma 14.5

Flet version

0.24.1

Python version

Running Python 3.12.3

Regression

I'm not sure / I don't know

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpackagingRelated to app packaging

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions