gritql
gritql copied to clipboard
Example of failing re-write that involves `add_import`
Not sure what's actually causing the failure, but failure appears when there are no other nodes except for the node to be changed
language python
class_definition($name, $body) as $C where {
$name <: `Config`,
$body <: block($statements),
$t = "",
$statements <: some bubble($t) assignment(left=$x, right=$y) as $A where {
$t += `$x=$y,`
},
$C => `ConfigDict($t)`,
add_import(source="pydantic", name="ConfigDict")
}
Fails on this code:
class Config:
a: int = 2
b: float = 5
Transforms to:
from pydantic import ConfigDict
class Config:
a: int = 2
b: float = 5
But works correctly if i add a comment node
# hello <--- Addnig a comment
class Config:
a: int = 2
b: float = 5
With output:
from pydantic import ConfigDict
# hello
ConfigDict(a=2,b=5,)
It seems like this is only an issue in the studio, as it works fine in a test.
In realiy, I assume files with only a single node are very rare.