Skip to content

Conversation

BobTheBuidler
Copy link
Contributor

@BobTheBuidler BobTheBuidler commented Oct 15, 2025

Currently, translate_len can determine the length of an RTuple at compile time

This PR extends this capability to all expressions supported by get_expr_length_value

This will constant fold the code example displayed in mypyc/mypyc#1152 without waiting for the implementation of #19886 which has a few steps ahead of it

Before:

def extend_and_specialize(items: list[dict[str, Any]]) -> None:
    types: Final[dict[str, Any]] = {i["name"]: i for i in items}
    types.update(
        {
            k[len("https://w3id.org/cwl/salad#") :]: v
            for k, v in types.items()
            if k.startswith("https://w3id.org/cwl/salad#")
        }
    )

After:

def extend_and_specialize(items: list[dict[str, Any]]) -> None:
    types: Final[dict[str, Any]] = {i["name"]: i for i in items}
    types.update(
        {
            k[27 : ]: v
            for k, v in types.items()
            if k.startswith("https://w3id.org/cwl/salad#")
        }
    )

Even after #19986, this will also work for some situations that constant folding cannot handle but get_expr_length can

Currently, `translate_len` can determine the length of an RTuple at compile time

This PR extends this capability to all expressions supported by `get_expr_length_value`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant