Commit 34373e3
authored
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:
```python
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:
```python
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.
1 parent 1cea058 commit 34373e3
2 files changed
+16
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| |||
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| 85 | + | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
| |||
222 | 224 | | |
223 | 225 | | |
224 | 226 | | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
230 | 231 | | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | 232 | | |
237 | 233 | | |
238 | 234 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3799 | 3799 | | |
3800 | 3800 | | |
3801 | 3801 | | |
| 3802 | + | |
| 3803 | + | |
| 3804 | + | |
| 3805 | + | |
| 3806 | + | |
| 3807 | + | |
| 3808 | + | |
| 3809 | + | |
| 3810 | + | |
| 3811 | + | |
0 commit comments