mirror of
https://github.com/rafamadriz/friendly-snippets
synced 2024-09-16 22:14:02 +02:00
python: merge base.json into python.json and change snippets (#454)
* python: merge base.json into python.json and streamline supported snippets.
This commit is contained in:
parent
637d90ec6a
commit
e11b09bf10
3 changed files with 209 additions and 285 deletions
14
package.json
14
package.json
|
@ -331,24 +331,20 @@
|
|||
},
|
||||
{
|
||||
"language": "python",
|
||||
"path": "./snippets/python/base.json"
|
||||
"path": "./snippets/python/python.json"
|
||||
},
|
||||
{
|
||||
"language": "python",
|
||||
"path": "./snippets/python/comprehension.json"
|
||||
},
|
||||
{
|
||||
"language": "python",
|
||||
"path": "./snippets/python/debug.json"
|
||||
},
|
||||
{
|
||||
"language": "python",
|
||||
"path": "./snippets/python/python.json"
|
||||
},
|
||||
{
|
||||
"language": "python",
|
||||
"path": "./snippets/python/unittest.json"
|
||||
},
|
||||
{
|
||||
"language": "python",
|
||||
"path": "./snippets/python/debug.json"
|
||||
},
|
||||
{
|
||||
"language": "pydoc",
|
||||
"path": "./snippets/python/pydoc.json"
|
||||
|
|
|
@ -1,178 +0,0 @@
|
|||
{
|
||||
"#!/usr/bin/env python": {
|
||||
"prefix": "env",
|
||||
"body": "#!/usr/bin/env python\n$0",
|
||||
"description": "Adds shebang line for default python interpreter."
|
||||
},
|
||||
"#!/usr/bin/env python3": {
|
||||
"prefix": "env3",
|
||||
"body": "#!/usr/bin/env python3\n$0",
|
||||
"description": "Adds shebang line for default python 3 interpreter."
|
||||
},
|
||||
"# -*- coding=utf-8 -*-": {
|
||||
"prefix": "enc",
|
||||
"body": "# -*- coding=utf-8 -*-\n$0",
|
||||
"description": "set default python2.x encoding specification to utf-8 as it is mentioned in pep-0263."
|
||||
},
|
||||
"# coding=utf-8": {
|
||||
"prefix": "enco",
|
||||
"body": "# coding=utf-8\n$0",
|
||||
"description": "Set default python3 encoding specification to utf-8, by default this is the encoding for python3.x as it is mentioned in pep-3120."
|
||||
},
|
||||
"from future import ...": {
|
||||
"prefix": "fenc",
|
||||
"body": [
|
||||
"# -*- coding: utf-8 -*-",
|
||||
"from __future__ import absolute_import, division, print_function, unicode_literals"
|
||||
],
|
||||
"description": "Import future statement definitions for python2.x scripts using utf-8 as encoding."
|
||||
},
|
||||
"from future import ... v1": {
|
||||
"prefix": "fenco",
|
||||
"body": [
|
||||
"# coding: utf-8",
|
||||
"from __future__ import absolute_import, division, print_function, unicode_literals"
|
||||
],
|
||||
"description": "Import future statement definitions for python3.x scripts using utf-8 as encoding."
|
||||
},
|
||||
"import": {
|
||||
"prefix": "im",
|
||||
"body": "import ${1:package/module}$0",
|
||||
"description": "Import a package or module"
|
||||
},
|
||||
"from ... import ...": {
|
||||
"prefix": "fim",
|
||||
"body": "from ${1:package/module} import ${2:names}$0",
|
||||
"description": "Import statement that allows individual objects from the module to be imported directly into the caller’s symbol table."
|
||||
},
|
||||
"class": {
|
||||
"prefix": "class",
|
||||
"body": ["class ${1:classname}(${2:object}):", "\t${3:pass}"],
|
||||
"description": "Code snippet for a class definition"
|
||||
},
|
||||
"New class": {
|
||||
"prefix": "classi",
|
||||
"body": "class ${1:ClassName}(${2:object}):\n\t\"\"\"${3:docstring for $1.}\"\"\"\n\tdef __init__(self, ${4:arg}):\n\t\t${5:super($1, self).__init__()}\n\t\tself.arg = arg\n\t\t$0",
|
||||
"description": "Code snippet for a class definition."
|
||||
},
|
||||
"New method": {
|
||||
"prefix": "defs",
|
||||
"body": "def ${1:mname}(self, ${2:arg}):\n\t${3:pass}$0",
|
||||
"description": "Code snippet for a class method definition."
|
||||
},
|
||||
"New method w/ return": {
|
||||
"prefix": "defst",
|
||||
"body": "def ${1:mname}(self, ${2:arg}) -> ${3:return_type}:\n\t${4:pass}$0",
|
||||
"description": "Code snippet for a class method definition."
|
||||
},
|
||||
"New function": {
|
||||
"prefix": "def",
|
||||
"body": "def ${1:fname}(${2:arg}):\n\t${3:pass}$0",
|
||||
"description": "Code snippet for function definition."
|
||||
},
|
||||
"New function w/ return": {
|
||||
"prefix": "deft",
|
||||
"body": "def ${1:fname}(${2:arg}) -> ${3:return_type}:\n\t${4:pass}$0",
|
||||
"description": "Code snippet for function definition."
|
||||
},
|
||||
"New async function": {
|
||||
"prefix": "adef",
|
||||
"body": "async def ${1:fname}(${2:arg}):\n\t${3:pass}$0",
|
||||
"description": "Code snippet for async function definition."
|
||||
},
|
||||
"New property": {
|
||||
"prefix": "property",
|
||||
"body": "@property\ndef ${1:foo}(self):\n \"\"\"${2:The $1 property.}\"\"\"\n ${3:return self._$1}\n@${4:$1}.setter\ndef ${5:$1}(self, value):\n ${6:self._$1} = value",
|
||||
"description": "New property: get and set via decorator"
|
||||
},
|
||||
"if": {
|
||||
"prefix": "if",
|
||||
"body": "if ${1:condition}:\n\t${2:pass}$0",
|
||||
"description": "Code snippet for the if statement."
|
||||
},
|
||||
"if/else": {
|
||||
"prefix": "if/else",
|
||||
"body": ["if ${1:condition}:", "\t${2:pass}", "else:", "\t${3:pass}"],
|
||||
"description": "Code snippet for an if statement with else"
|
||||
},
|
||||
"elif": {
|
||||
"prefix": "elif",
|
||||
"body": ["elif ${1:expression}:", "\t${2:pass}"],
|
||||
"description": "Code snippet for an elif"
|
||||
},
|
||||
"else": {
|
||||
"prefix": "else",
|
||||
"body": ["else:", "\t${1:pass}"],
|
||||
"description": "Code snippet for an else"
|
||||
},
|
||||
"for": {
|
||||
"prefix": "for",
|
||||
"body": "for ${1:value} in ${2:iterable}:\n\t${3:pass}$0",
|
||||
"description": "Code snippet to create a for loop structure."
|
||||
},
|
||||
"for/else": {
|
||||
"prefix": "for/else",
|
||||
"body": [
|
||||
"for ${1:target_list} in ${2:expression_list}:",
|
||||
"\t${3:pass}",
|
||||
"else:",
|
||||
"\t${4:pass}"
|
||||
],
|
||||
"description": "Code snippet for a for loop with else"
|
||||
},
|
||||
"while": {
|
||||
"prefix": "while",
|
||||
"body": "while ${1:condition}:\n\t${2:pass}$0",
|
||||
"description": "Code snippet to create a while loop structure."
|
||||
},
|
||||
"while/else": {
|
||||
"prefix": "while/else",
|
||||
"body": [
|
||||
"while ${1:expression}:",
|
||||
"\t${2:pass}",
|
||||
"else:",
|
||||
"\t${3:pass}"
|
||||
],
|
||||
"description": "Code snippet for a while loop with else"
|
||||
},
|
||||
"try:except:": {
|
||||
"prefix": "try",
|
||||
"body": "try:\n\t${1:pass}\nexcept ${2:Exception} as ${3:e}:\n\t${4:raise $3}$0",
|
||||
"description": "Code Snippet for a try and except blocks."
|
||||
},
|
||||
"try:except:else:finally": {
|
||||
"prefix": "tryef",
|
||||
"body": "try:\n\t${1:pass}\nexcept${2: ${3:Exception} as ${4:e}}:\n\t${5:raise}\nelse:\n\t${6:pass}\nfinally:\n\t${7:pass}$0",
|
||||
"description": "Code Snippet for a try/except/finally with else statement."
|
||||
},
|
||||
"try:except:else": {
|
||||
"prefix": "trye",
|
||||
"body": "try:\n\t${1:pass}\nexcept ${2:Exception} as ${3:e}:\n\t${4:raise $3}\nelse:\n\t${5:pass}$0",
|
||||
"description": "Code Snippet for a try/except with else statement."
|
||||
},
|
||||
"try:except:finally": {
|
||||
"prefix": "tryf",
|
||||
"body": "try:\n\t${1:pass}\nexcept ${2:Exception} as ${3:e}:\n\t${4:raise $3}\nfinally:\n\t${5:pass}$0",
|
||||
"description": "Code Snippet for a try/except/finally."
|
||||
},
|
||||
"with": {
|
||||
"prefix": "with",
|
||||
"body": ["with ${1:expression} as ${2:target}:", "\t${3:pass}"],
|
||||
"description": "Code snippet for a with statement"
|
||||
},
|
||||
"self": {
|
||||
"prefix": "s",
|
||||
"body": "self.$0",
|
||||
"description": "Shortend snippet to reference the self property in an object."
|
||||
},
|
||||
"__magic__": {
|
||||
"prefix": "__",
|
||||
"body": "__${1:init}__$0",
|
||||
"description": "Code snippet to create magic methods."
|
||||
},
|
||||
"if __name__ == \"__main__\"": {
|
||||
"prefix": "ifmain",
|
||||
"body": "if __name__ == \"__main__\":\n\t${1:main()}$0",
|
||||
"description": "Create implicitly all the code at the top level using the __name__ special variable."
|
||||
}
|
||||
}
|
|
@ -1,128 +1,234 @@
|
|||
{
|
||||
"try/except": {
|
||||
"prefix": "try/except",
|
||||
"body": [
|
||||
"try:",
|
||||
"\t${1:pass}",
|
||||
"except ${2:expression} as ${3:identifier}:",
|
||||
"\t${4:pass}"
|
||||
],
|
||||
"description": "Code snippet for a try/except statement"
|
||||
"#!/usr/bin/env pythonX": {
|
||||
"prefix": "#env",
|
||||
"body": "#!/usr/bin/env python$0",
|
||||
"description": "Shebang line for the first python in PATH"
|
||||
},
|
||||
"try/finally": {
|
||||
"prefix": "try/finally",
|
||||
"body": ["try:", "\t${1:pass}", "finally:", "\t${2:pass}"],
|
||||
"description": "Code snippet for a try/finally statement"
|
||||
"pyright ignore line": {
|
||||
"prefix": "#ignore",
|
||||
"body": "# pyright: ignore[$0]",
|
||||
"description": "Ignore specific line diagnostic in pyright (ignore all is unsafe)"
|
||||
},
|
||||
"try/except/else": {
|
||||
"prefix": "try/except/else",
|
||||
"body": [
|
||||
"try:",
|
||||
"\t${1:pass}",
|
||||
"except ${2:expression} as ${3:identifier}:",
|
||||
"\t${4:pass}",
|
||||
"else:",
|
||||
"\t${5:pass}"
|
||||
],
|
||||
"description": "Code snippet for a try/except/else statement"
|
||||
"Multiline string": {
|
||||
"prefix": "#",
|
||||
"body": ["\"\"\"$0", "\"\"\""],
|
||||
"description": "Snippet to avoid autopair plugin annoyances when typing multiple \""
|
||||
},
|
||||
"try/except/finally": {
|
||||
"prefix": "try/except/finally",
|
||||
"body": [
|
||||
"try:",
|
||||
"\t${1:pass}",
|
||||
"except ${2:expression} as ${3:identifier}:",
|
||||
"\t${4:pass}",
|
||||
"finally:",
|
||||
"\t${5:pass}"
|
||||
],
|
||||
"description": "Code snippet for a try/except/finally statement"
|
||||
"One-line multiline string": {
|
||||
"prefix": "##",
|
||||
"body": "\"\"\"$0\"\"\"",
|
||||
"description": "Snippet to avoid autopair plugin annoyances when typing multiple \""
|
||||
},
|
||||
"try/except/else/finally": {
|
||||
"prefix": "try/except/else/finally",
|
||||
"body": [
|
||||
"try:",
|
||||
"\t${1:pass}",
|
||||
"except ${2:expression} as ${3:identifier}:",
|
||||
"\t${4:pass}",
|
||||
"else:",
|
||||
"\t${5:pass}",
|
||||
"finally:",
|
||||
"\t${6:pass}"
|
||||
],
|
||||
"description": "Code snippet for a try/except/else/finally statement"
|
||||
"self": {
|
||||
"prefix": "s",
|
||||
"body": "self.$0",
|
||||
"description": "Snippet to reference the self property in an object"
|
||||
},
|
||||
"def(class method)": {
|
||||
"prefix": "def class method",
|
||||
"body": [
|
||||
"def ${1:funcname}(self, ${2:parameter_list}):",
|
||||
"\t${3:pass}"
|
||||
],
|
||||
"description": "Code snippet for a class method"
|
||||
"__magic__": {
|
||||
"prefix": "__",
|
||||
"body": "__${1:init}__$0",
|
||||
"description": "Create magic method"
|
||||
},
|
||||
"def(static class method)": {
|
||||
"prefix": "def static class method",
|
||||
"body": [
|
||||
"@staticmethod",
|
||||
"def ${1:funcname}(${2:parameter_list}):",
|
||||
"\t${3:pass}"
|
||||
],
|
||||
"description": "Code snippet for a static class method"
|
||||
"if __name__ == __main__": {
|
||||
"prefix": "ifmain",
|
||||
"body": ["if __name__ == \"__main__\":", "\t${1:main()}"],
|
||||
"description": "Execute code if the file is executed directly"
|
||||
},
|
||||
"def(abstract class method)": {
|
||||
"prefix": "def abstract class method",
|
||||
"import": {
|
||||
"prefix": "import",
|
||||
"body": "import ${1:datetime}",
|
||||
"description": "Import a package or module"
|
||||
},
|
||||
"from ... import ...": {
|
||||
"prefix": "fromim",
|
||||
"body": "from ${1:pathlib} import ${2:Path}",
|
||||
"description": "Import individual objects directly into the caller’s symbol table"
|
||||
},
|
||||
"if": {
|
||||
"prefix": "if",
|
||||
"body": ["if ${1:condition}:", "\t${2:pass}"],
|
||||
"description": "if statement"
|
||||
},
|
||||
"elif": {
|
||||
"prefix": "elif",
|
||||
"body": ["elif ${1:expression}:", "\t${2:pass}"],
|
||||
"description": "elif statement"
|
||||
},
|
||||
"else": {
|
||||
"prefix": "else",
|
||||
"body": ["else:", "\t${1:pass}"],
|
||||
"description": "else statement"
|
||||
},
|
||||
"if/else": {
|
||||
"prefix": "ifelse",
|
||||
"body": ["if ${1:condition}:", "\t${2:pass}", "else:", "\t${3:pass}"],
|
||||
"description": "if statement with else"
|
||||
},
|
||||
"match/case": {
|
||||
"prefix": "match",
|
||||
"body": [
|
||||
"def ${1:funcname}(self, ${2:parameter_list}):",
|
||||
"\traise NotImplementedError"
|
||||
"match ${1:expression}:",
|
||||
"\tcase ${2:pattern}:",
|
||||
"\t\t${3:pass}"
|
||||
],
|
||||
"description": "Code snippet for an abstract class method"
|
||||
"description": "match/case statements"
|
||||
},
|
||||
"case": {
|
||||
"prefix": "case",
|
||||
"body": ["case ${2:pattern}:", "\t${3:pass}"],
|
||||
"description": "case block"
|
||||
},
|
||||
"case wildcard": {
|
||||
"prefix": "casew",
|
||||
"body": ["case _:", "\t${1:pass}"],
|
||||
"description": "case wildcard block if other cases fail"
|
||||
},
|
||||
"while": {
|
||||
"prefix": "while",
|
||||
"body": ["while ${1:condition}:", "\t${2:pass}"],
|
||||
"description": "while loop"
|
||||
},
|
||||
"for": {
|
||||
"prefix": "for",
|
||||
"body": ["for ${1:value} in ${2:iterable}:", "\t${3:pass}"],
|
||||
"description": "for loop"
|
||||
},
|
||||
"for w/ range": {
|
||||
"prefix": "forr",
|
||||
"body": ["for ${1:value} in range($2):", "\t${3:pass}"],
|
||||
"description": "for loop that iterates over range of integers"
|
||||
},
|
||||
"with": {
|
||||
"prefix": "with",
|
||||
"body": ["with ${1:expression} as ${2:target}:", "\t${3:pass}"],
|
||||
"description": "'with' statement"
|
||||
},
|
||||
"lambda": {
|
||||
"prefix": "lambda",
|
||||
"body": ["lambda ${1:parameter_list}: ${2:expression}"],
|
||||
"description": "Code snippet for a lambda statement"
|
||||
"description": "lambda statement"
|
||||
},
|
||||
"if(main)": {
|
||||
"prefix": "__main__",
|
||||
"body": ["if __name__ == \"__main__\":", " ${1:pass}"],
|
||||
"description": "Code snippet for a `if __name__ == \"__main__\": ...` block"
|
||||
"Function": {
|
||||
"prefix": "def",
|
||||
"body": ["def ${1:fname}($2):", "\t${3:pass}"],
|
||||
"description": "Function definition"
|
||||
},
|
||||
"async/def": {
|
||||
"prefix": "async/def",
|
||||
"Function w/ return type": {
|
||||
"prefix": "deft",
|
||||
"body": ["def ${1:fname}($2) -> ${3:None}:", "\t${4:pass}"],
|
||||
"description": "Function definition with return type"
|
||||
},
|
||||
"class": {
|
||||
"prefix": "class",
|
||||
"body": ["class ${1:classname}:", "\t${2:pass}"],
|
||||
"description": "Class definition"
|
||||
},
|
||||
"Derived class": {
|
||||
"prefix": "classd",
|
||||
"body": ["class ${1:classname}($2):", "\t${3:pass}"],
|
||||
"description": "Class definition with inheritance"
|
||||
},
|
||||
"class template": {
|
||||
"prefix": "classi",
|
||||
"body": [
|
||||
"async def ${1:funcname}(${2:parameter_list}):",
|
||||
"\t${3:pass}"
|
||||
"class ${1:ClassName}($2):",
|
||||
"\t\"\"\"${3:docstring for $1.}\"\"\"",
|
||||
"\tdef __init__(self, ${4:arg}):",
|
||||
"\t\t${5:super($1, self).__init__()}",
|
||||
"\t\tself.$4 = $4$0"
|
||||
],
|
||||
"description": "Code snippet for an async statement"
|
||||
"description": "Class definition template"
|
||||
},
|
||||
"async/for": {
|
||||
"prefix": "async/for",
|
||||
"body": ["async for ${1:target} in ${2:iter}:", "\t${3:block}"],
|
||||
"description": "Code snippet for an async for statement"
|
||||
"Method": {
|
||||
"prefix": "defs",
|
||||
"body": ["def ${1:mname}(self$2):", "\t${3:pass}"],
|
||||
"description": "Class method definition"
|
||||
},
|
||||
"async/for/else": {
|
||||
"prefix": "async/for/else",
|
||||
"Method w/ return type": {
|
||||
"prefix": "defst",
|
||||
"body": ["def ${1:mname}(self$2) -> ${3:None}:", "\t${4:pass}"],
|
||||
"description": "Class method definition"
|
||||
},
|
||||
"property template": {
|
||||
"prefix": "property",
|
||||
"body": [
|
||||
"async for ${1:target} in ${2:iter}:",
|
||||
"\t${3:block}",
|
||||
"@property",
|
||||
"def ${1:pname}(self):",
|
||||
"\t\"\"\"${2:The $1 property.}\"\"\"",
|
||||
"\t${3:return self._$1}",
|
||||
"",
|
||||
"@${4:$1}.setter",
|
||||
"def ${5:$1}(self, value):",
|
||||
"\t${6:self._$1} = value"
|
||||
],
|
||||
"description": "New property: get and set via decorator"
|
||||
},
|
||||
"except": {
|
||||
"prefix": "except",
|
||||
"body": ["except$1:", "\t${2:pass}"],
|
||||
"description": "except statement"
|
||||
},
|
||||
"except as": {
|
||||
"prefix": "exceptas",
|
||||
"body": ["except ${1:Exception} as ${2:e}:", "\t${3:raise $2}"],
|
||||
"description": "'except as' statement"
|
||||
},
|
||||
"try/except": {
|
||||
"prefix": "try",
|
||||
"body": [
|
||||
"try:",
|
||||
"\t${1:pass}",
|
||||
"except ${2:Exception} as ${3:e}:",
|
||||
"\t${4:raise $3}"
|
||||
],
|
||||
"description": "try/except blocks"
|
||||
},
|
||||
"try/except/else": {
|
||||
"prefix": "trya",
|
||||
"body": [
|
||||
"try:",
|
||||
"\t${1:pass}",
|
||||
"except ${2:Exception} as ${3:e}:",
|
||||
"\t${4:raise $3}",
|
||||
"else:",
|
||||
"\t${4:block}"
|
||||
"\t${5:pass}"
|
||||
],
|
||||
"description": "Code snippet for an async for statement with else"
|
||||
"description": "try/except/else blocks"
|
||||
},
|
||||
"async/with": {
|
||||
"prefix": "async/with",
|
||||
"body": ["async with ${1:expr} as ${2:var}:", "\t${3:block}"],
|
||||
"description": "Code snippet for an async with statement"
|
||||
"try/except/finally": {
|
||||
"prefix": "tryf",
|
||||
"body": [
|
||||
"try:",
|
||||
"\t${1:pass}",
|
||||
"except ${2:Exception} as ${3:e}:",
|
||||
"\t${4:raise $3}",
|
||||
"finally:",
|
||||
"\t${5:pass}"
|
||||
],
|
||||
"description": "try/except/finally blocks"
|
||||
},
|
||||
"add/new/cell": {
|
||||
"prefix": "add/new/cell",
|
||||
"try/except/else/finally": {
|
||||
"prefix": "tryef",
|
||||
"body": [
|
||||
"try:",
|
||||
"\t${1:pass}",
|
||||
"except${2: ${3:Exception} as ${4:e}}:",
|
||||
"\t${5:raise}",
|
||||
"else:",
|
||||
"\t${6:pass}",
|
||||
"finally:",
|
||||
"\t${7:pass}"
|
||||
],
|
||||
"description": "try/except/else/finally blocks"
|
||||
},
|
||||
"Jupyter cell": {
|
||||
"prefix": "#cell",
|
||||
"body": "# %%",
|
||||
"description": "Code snippet to add a new cell"
|
||||
"description": "Add a new cell"
|
||||
},
|
||||
"mark/markdown": {
|
||||
"prefix": "mark/markdown",
|
||||
"Jupyter markdown cell": {
|
||||
"prefix": "#mark",
|
||||
"body": "# %% [markdown]",
|
||||
"description": "Code snippet to add a new markdown cell"
|
||||
"description": "Add a new markdown cell"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue