fix property and slotted class python snippets

• `rwprop` did not work at all for me (messed up expansion)
  and did not honor `ultisnips_python_quoting_style`.
• slotclass assigns to variables beginning with an underscore
  in its init function and thus the slots have to begin
  with an underscore too.
This commit is contained in:
Johann Klähn 2013-07-03 18:45:28 +02:00
parent 5a9233f56c
commit f2009bd724

View File

@ -102,7 +102,7 @@ def write_init_body(args, parents, snip):
def write_slots_args(args, snip): def write_slots_args(args, snip):
args = ['"%s"' % arg for arg in args] args = ['"_%s"' % arg for arg in args]
snip += '__slots__ = (%s,)' % ', '.join(args) snip += '__slots__ = (%s,)' % ', '.join(args)
endglobal endglobal
@ -376,14 +376,16 @@ endsnippet
############## ##############
snippet roprop "Read Only Property" b snippet roprop "Read Only Property" b
@property @property
def ${1:property}(self): def ${1:name}(self):
${2:return self._$1}$0 ${2:return self._$1}$0
endsnippet endsnippet
snippet rwprop "Read write property" b snippet rwprop "Read write property" b
def ${1:property}(): def ${1:name}():
${2/.+/(?0:`!p snip.rv = tripple_quotes(snip)`)/}${2:The RW property $1}`!p if t[2]: `!p snip.rv = tripple_quotes(snip) if t[2] else ''
snip.rv += '"""' `${2:@todo: Docstring for $1}`!p
if t[2]:
snip.rv = tripple_quotes(snip)
snip >> 1 snip >> 1
snip += "" snip += ""
else: else:
@ -392,7 +394,7 @@ else:
def fset(self, value): def fset(self, value):
self._$1 = value self._$1 = value
return locals() return locals()
$1 = property(**$1()) $1 = property(**$1(), doc=$1.__doc__)
endsnippet endsnippet