| 📦 Turbo Python 6fc62ea k33g 9h ago | 1 | # turbo-python snippets. |
| 2 | # |
| 3 | # Each [[snippet]] becomes one line of the Snippets menu. Snippets sharing a |
| 4 | # group appear together in a submenu of that name; one with no group goes into |
| 5 | # %s. A snippet is inserted at the cursor, and every line after the |
| 6 | # first is indented to match the line you inserted it on. |
| 7 | # |
| 8 | # languages restricts a snippet to files of those kinds, by the names the |
| 9 | # editor uses: python, toml, yaml, markdown, javascript, html, xml, dockerfile, |
| 10 | # bash. Leave it out and the snippet is offered everywhere. |
| 11 | # |
| 12 | # Bodies are indented with four spaces, never a tab: that is what PEP 8 asks |
| 13 | # for, and a tab inserted into a file indented with spaces is an indentation |
| 14 | # error rather than a formatting quibble. |
| 15 | # |
| 16 | # Your own snippets, shared across every project, go in: |
| 17 | # %s |
| 18 | |
| 19 | [[snippet]] |
| 20 | name = "main guard" |
| 21 | group = "Python" |
| 22 | languages = ["python"] |
| 23 | body = """ |
| 24 | def main() -> None: |
| 25 | ... |
| 26 | |
| 27 | |
| 28 | if __name__ == "__main__": |
| 29 | main()""" |
| 30 | |
| 31 | [[snippet]] |
| 32 | name = "class" |
| 33 | group = "Python" |
| 34 | languages = ["python"] |
| 35 | body = """ |
| 36 | class Thing: |
| 37 | def __init__(self, name: str) -> None: |
| 38 | self.name = name""" |
| 39 | |
| 40 | [[snippet]] |
| 41 | name = "match" |
| 42 | group = "Python" |
| 43 | languages = ["python"] |
| 44 | body = """ |
| 45 | match value: |
| 46 | case 0: |
| 47 | ... |
| 48 | case _: |
| 49 | ...""" |
| 50 | |
| 51 | [[snippet]] |
| 52 | name = "try / except" |
| 53 | group = "Python" |
| 54 | languages = ["python"] |
| 55 | body = """ |
| 56 | try: |
| 57 | ... |
| 58 | except ValueError as error: |
| 59 | raise SystemExit(error) from error""" |
| 60 | |
| 61 | [[snippet]] |
| 62 | name = "dataclass" |
| 63 | group = "Python" |
| 64 | languages = ["python"] |
| 65 | body = """ |
| 66 | @dataclass(frozen=True) |
| 67 | class Thing: |
| 68 | name: str |
| 69 | count: int = 0""" |
| 70 | |
| 71 | [[snippet]] |
| 72 | name = "test" |
| 73 | group = "Python" |
| 74 | languages = ["python"] |
| 75 | body = """ |
| 76 | def test_it_works() -> None: |
| 77 | assert 1 + 1 == 2""" |
| 78 | |
| 79 | [[snippet]] |
| 80 | group = "General" |
| 81 | name = "Hello" |
| 82 | body = "Hello!!!" |
| 83 | |
| 84 | [[snippet]] |
| 85 | group = "Markdown" |
| 86 | name = "Image" |
| 87 | languages = ["markdown"] |
| 88 | body = "" |