-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: repair some bugs with add_import in Python (#231)
- Loading branch information
Showing
3 changed files
with
88 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Test for ensuring new imports go to the right place, from [this issue](https://github.com/getgrit/gritql/issues/449). | ||
|
||
```grit | ||
engine marzano(0.1) | ||
language python | ||
`$x = 1` where { | ||
add_import(source="typing_extensions", name="Self"), | ||
add_import(source="pydantic", name="model_validator"), | ||
} | ||
``` | ||
|
||
Input: | ||
|
||
```python | ||
import math | ||
x = 1 | ||
``` | ||
|
||
Expected output: | ||
|
||
```python | ||
import math | ||
from typing_extensions import Self | ||
from pydantic import model_validator | ||
|
||
x = 1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Test for adding multiple imports to the same library, for [this issue](https://github.com/getgrit/gritql/issues/450). | ||
|
||
```grit | ||
engine marzano(0.1) | ||
language python | ||
`x = 1` as $SELF where { | ||
add_import(source="pydantic", name="Self"), | ||
add_import(source="pydantic", name="pydantic1"), | ||
} | ||
``` | ||
|
||
Input: | ||
|
||
```python | ||
from pydantic import BaseModel, Extra, Field, root_validator | ||
|
||
x = 1 | ||
``` | ||
|
||
Expected Output: | ||
|
||
```python | ||
from pydantic import BaseModel, Extra, Field, root_validator, Self, pydantic1 | ||
|
||
x = 1 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters