Skip to content

basic Python porting to Mojo #3329

Locked Answered by soraros
rickysarraf asked this question in Q&A
Jul 29, 2024 · 1 comments · 3 replies
Discussion options

You must be logged in to vote

In Mojo, a string literal ("something") has the type StringLiteral (this is about to change to match Python). They can't be concatenated at compile time. The fix is simple: convert them to String as follows:

...
    var parser = Py_argparse.ArgumentParser(
        prog=app_name,
        description=String("Offline APT Package Manager") + " - " + version,
        epilog=String(myCopyright) + " - " + terminal_license,
    )
...

Perhaps the error message is less helpful on version 24.4 (I don't have it installed), but the error on the nightly build reads:

/__w/modular/modular/open-source/mojo/stdlib/stdlib/builtin/string_literal.mojo:93:45: error: failed to legalize operation 'pop.string.con…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@rickysarraf
Comment options

@soraros
Comment options

Answer selected by rickysarraf
@rickysarraf
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants