gritql icon indicating copy to clipboard operation
gritql copied to clipboard

Example of failing re-write that involves `add_import`

Open eyurtsev opened this issue 1 year ago • 1 comments

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,)

eyurtsev avatar Aug 06 '24 20:08 eyurtsev

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.

morgante avatar Aug 06 '24 23:08 morgante