cstrap/python-snippets

new-style properties

BlacKCaT27 opened this issue · 2 comments

I found this library through VSCode extensions tab and it's great. My only complaint is that the property snippet uses the more basic non-decorator based property format. So I wrote a new snippet body which defines the newer decorator-based format:

    "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"
    },

This will produce a python property which looks like this:

    @property
    def foo(self):
        """The foo property."""
        return self._foo
    @foo.setter
    def foo(self, value):
        self._foo = value

Leaving this here in case anyone wants this style property. You can edit your snippets collection locally by editing base.json under

Windows %USERPROFILE%\.vscode\extensions\cstrap.python-snippets-0.0.5\snippets
Mac ~/.vscode/extensions\cstrap.python-snippets-0.0.5\snippets
Linux ~/.vscode/extensions\cstrap.python-snippets-0.0.5\snippets

I don't really have the time nor inclination to do a pull request since the author would need to decide what to call this form anyway, so I'll leave that for the owner :)

I am the said "anyone". Thanks for this, esp. as I'm new to properties and the original code doesn't function out of the box whereas yours does.

Added to version 0.0.8.