Skip to content

Commit

Permalink
Merge remote-tracking branch 'python/main' into consolidate
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante committed Dec 8, 2023
2 parents c6a421e + eb9648f commit c910bd7
Show file tree
Hide file tree
Showing 32 changed files with 3,131 additions and 0 deletions.
111 changes: 111 additions & 0 deletions .grit/patterns/_test_add_multiple_bare_imports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
title: Test - add multiple bare imports
---

```grit
engine marzano(0.1)
language python
`$_` where {
$import_math = "math",
$import_math <: ensure_bare_import(),
$import_re = "re",
$import_re <: ensure_bare_import(),
$import_json = "json",
$import_json <: ensure_bare_import(),
}
```

## Add all imports if none is imported


```python
```

```python
import math
import re
import json


```

## Add missing imports

```python
import math
import re
```

```python
import json

import math
import re
```

## Add missing imports

```python
import json
import re
```

```python
import math

import json
import re
```

## Add missing import, all in one line

```python
import json, math
```

```python
import re

import json, math
```


## Don't add duplicate imports

```python
import math
import json
import re
```

```python
import math
import json
import re
```

## Don't add duplicate imports (different order)

```python
import re
import json
import math
```

```python
import re
import json
import math
```

## Don't add duplicate imports, all in one line

```python
import json, math, re
```

```python
import json, math, re
```
36 changes: 36 additions & 0 deletions .grit/patterns/_test_add_one_bare_import.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Test - add one bare import
---

```grit
engine marzano(0.1)
language python
`$_` where {
$import = "math",
$import <: ensure_bare_import(),
}
```

## Add one bare import


```python
```

```python
import math


```

## Do not add duplicate bare import

```python
import math
```

```python
import math
```
58 changes: 58 additions & 0 deletions .grit/patterns/_test_ensure_import_from.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: Test - ensure import from
---

```grit
engine marzano(0.1)
language python
`$_` where {
$import = "prod",
$import <: ensure_import_from(source = `math`),
}
```

## Add missing import


```python
```

```python
from math import prod


```

## Add one more name to source

```python
from math import log
```

```python
from math import log, prod
```

## Keep existing import

```python
from math import prod
```

```python
from math import prod
```

## Add from import even if there is a bare import

```python
import math
```

```python
from math import prod

import math
```
93 changes: 93 additions & 0 deletions .grit/patterns/_test_is_bare_imported.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
title: Test - is bare imported
---

```grit
engine marzano(0.1)
language python
integer() as $int where {
$math = "math",
$re = "re",
$json = "json",
if ($math <: is_bare_imported()) {
$has_math = "true"
}
else {
$has_math = "false"
},
if ($re <: is_bare_imported()) {
$has_re = "true"
}
else {
$has_re = "false"
},
if ($json <: is_bare_imported()) {
$has_json = "true"
}
else {
$has_json = "false"
}
} => `$has_math, $has_re, $has_json`
```


## All bare imports missing

```python
42
```

```python
false, false, false
```

## Two bare imports present

```python
import math
import json

42
```

```python
import math
import json

true, false, true
```

## Imported bare import as part of a list

```python
import json, re

42
```

```python
import json, re

false, true, true
```

## From import is not a bare import

```python
from math import log
from re import match

import json

42
```

```python
from math import log
from re import match

import json

false, false, true
```
Loading

0 comments on commit c910bd7

Please sign in to comment.