I was trying to do the same thing, found your answer, implemented it and since I'm learning Regex, though it would be nice to try to generalize for atribute typing. Came up with the following:
"Class Defininition": {
"prefix": "clss",
"body": [
"class ${1:ClassName}${2/[(][)]/$1/g}:",
"\t'''\n\tClass $1: $3\n\t'''\n",
"\tdef __init__(self, ${4/([^self \\s]*|)/$1/g}):",
"\t\t${4/(^\\w+|(?<=,\\s)\\w+)(.*?,\\s|:.*|=.*|$)/self.$1 = $1${4:\n\t\t}/g}",
"\t\t$0"
],
"description": "Initialize Class"
}
The sequence is:
$1
- Class name (also fills default docstring)
$2
- Inheritance (need to type in the parentheses. Here I wanted to set them as default, and remove it if empty. I know it still works with empty parentheses, but I couldn't make it delete if empty and not typed inside $4
)
$3
- Class description
$4
- Attribute declaration, including typing following the syntax in Support for type hints
Example:
class ClassName:
'''
Class ClassName:
'''
def __init__(self, foo, bar: int, baz, default=10):
self.foo = foo
self.bar = bar
self.baz = baz
self.default = default