vimrc

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules

commit b0b901a5a50cc979af87b67c305e0a67a5aa9517
parent 6386d7d6ae67f1553aae55ab04a3a7474cc675a5
Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe>
Date:   Thu, 26 Jan 2023 23:00:41 -0500

Updated python snippets

Diffstat:
MUltiSnips/python.snippets | 122++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 102 insertions(+), 20 deletions(-)

diff --git a/UltiSnips/python.snippets b/UltiSnips/python.snippets @@ -20,9 +20,13 @@ for ${1:item} in ${2:iterable}: endsnippet # --------------------------------------------- # +snippet sized "Sized" b +def __len__(self): + ${2:pass} +endsnippet -snippet seq "methods for emulating a sequence type" b -def __getitem__(self, key): +snippet sequence "Sequence" b +def __getitem__(self, index): ${1:pass} def __len__(self): @@ -30,7 +34,7 @@ def __len__(self): endsnippet -snippet context "context manager methods" b +snippet contextmanager "AbstractContextManager" b def __enter__(self): ${1:pass} @@ -39,7 +43,7 @@ def __exit__(self, exc_type, exc_value, traceback): endsnippet -snippet desc "methods implementing descriptors" b +snippet desc "Descriptor" b def __get__(self, instance, owner): ${1:pass} @@ -51,7 +55,7 @@ def __delete__(self, instance): endsnippet -snippet repr "method implementing string representation" b +snippet repr "__repr__" b def __repr__(self): ${1:pass} endsnippet @@ -95,19 +99,25 @@ endglobal snippet def "function with docstrings" b def ${1:function}(`!p if snip.indent: - snip.rv = 'self' + (", " if len(t[2]) else "")`${2:arg1}) -> ${3:None}: - """${4:TODO: Docstring for $1.}`!p + snip.rv = 'self' + (", " if len(t[2]) else "")`${2:arg1: Type1}) -> ${3:None}:`!p snip.rv = "" -snip >> 1 +if t[4]: + snip >> 1 + snip += '"""' + snip += "" +`${4:TODO: Docstring for $1.}`!p +snip.rv = "" +if t[4]: + snip >> 1 -args = get_args(t[2]) -for arg in args: - snip += ":param {}: TODO".format(arg) + args = get_args(t[2]) + for arg in args: + snip += ":param {}: TODO".format(arg.name) -if t[3] != "None": - snip += ":returns: TODO" + if t[3] != "None": + snip += ":returns: TODO" -snip += '"""' + snip += '"""' ` ${5:${VISUAL:pass}} endsnippet @@ -125,7 +135,7 @@ snip >> 1 args = get_args(t[2]) for arg in args: - snip += ":param {}: TODO".format(arg) + snip += ":param {}: TODO".format(arg.name) if t[3] != "None": snip += ":returns: TODO" @@ -144,7 +154,7 @@ snip >> 1 args = get_args(t[2]) for arg in args: - snip += ":param {}: TODO".format(arg) + snip += ":param {}: TODO".format(arg.name) if t[3] != "None": snip += ":returns: TODO" @@ -161,23 +171,95 @@ class ${1:MyClass}`!p snip.rv = "(" if t[2] else ""`${2:Parent}`!p snip.rv = ")" snip.rv = "" snip >> 1 args = get_args(t[4]) +if args: + snip.rv += "\n" + snip.mkline("") for arg in args: - snip += ":param %s: TODO" % arg + snip += ":param {}: TODO".format(arg.name) ` """ - - def __init__(self$4) -> None:`!p + def __init__(self`!p snip.rv = ", " if t[4] else ""`${4:arg1: Type1}) -> None:`!p snip >> 2 snip.rv = "" if t[2]: # If has parent class snip += "super().__init__()" + +if args and t[2]: snip.rv += '\n' + snip.mkline("") for arg in args: # Initialize attributes - snip += "self._{} = {}".format(arg, arg) + snip += "self._{} = {}".format(arg.name, arg.name) ` $5 endsnippet + + +snippet dcl "dataclass" b +@dataclass +class ${1:MyClass}: + """${2:Docstring for $1.} + """ + ${3:var_1}: ${4:int} + ${5:var_2}: ${6:float} = ${7:0} + + def ${8:total}(self): -> $6: + return ${0:self.$3 * self.$5} +endsnippet + +# --------------------------------------------- # + +snippet np "import numpy as np" b +import numpy as np +from numpy.random import default_rng +$0 +endsnippet + +snippet plt "import matplotlib.pyplot as plt" b +import matplotlib.pyplot as plt +$0 +endsnippet + +snippet torch "import torch" b +import torch +import torch.nn as nn +import torch.optim as optim +import torch.nn.functional as F +$0 +endsnippet + +snippet gym "import gymnasium as gym" b +import gymnasium as gym +$0 +endsnippet + +# --------------------------------------------- # + +snippet no_grad "with torch.no_grad()" b +with torch.no_grad(): + ${0:${VISUAL:pass}} +endsnippet + +# --------------------------------------------- # + +snippet if "If" b +if ${1:condition}: + ${2:${VISUAL:pass}} +endsnippet + +snippet ife "If / Else" b +if ${1:condition}: + ${2:${VISUAL:pass}} +else: + ${3:pass} +endsnippet + +snippet ifee "If / Elif / Else" b +if ${1:condition}: + ${2:${VISUAL:pass}} +elif ${3:condition}: + ${4:pass} +else: + ${5:pass} +endsnippet