python-snippets icon indicating copy to clipboard operation
python-snippets copied to clipboard

Probably some mistake in `class` snippet

Open piotrgredowski opened this issue 3 years ago • 3 comments

Hi, class snippet is not working correctly. obraz Expression from here is such complicated that I will not try to understand it :) but it's not working correctly. There's a problem with this second arg. It's not where it should be. I've added PR solving that issue.

piotrgredowski avatar Jun 29 '22 20:06 piotrgredowski

Hi @piotrgredowski

The snippet is working fine, you just need to use its auto-completion feature (the reason why its code is complicated ^^)
As shown in the video, using the tab key, you can scroll through the class definition parts and modify them. If you modify the args of the __init__ function, they will automatically be updated.

If you don't need any arguments, just remove arg in the function definition, press tab and the second arg will be removed. (As shown in the second example of the video.)

Hope this helps !

PS: If you experience problems with the auto-formatting of certain snippets, make sure you have the option editor.tabCompletion set on onlySnippets or on.

https://user-images.githubusercontent.com/60932251/182392271-ce37dec4-f1b2-474b-a028-6dc34a8f1f8b.mp4

pchoisel avatar Aug 02 '22 13:08 pchoisel

Hi! The class snippet doesn't allow us to write the type of the argument and we receive generated code that requires correction: Screenshot_20231221_213026

I suggest considering a small change that solves this problem for me:

	"Class": {
		"prefix": "class",
		"body": [
			"class ${1:ClassName}(${2:object}):",
			"\t\"\"\"${3:docstring for $1.}\"\"\"\n",
			"\tdef __init__(self, ${4:arg}) -> None:",
			"\t\t\"\"\"${5:Constructor.}\"\"\"",
			"\t\t${6:super($1, self).__init__()}",
			"\t\t${4/\\s*([^,:=]+)([^,=]+)?(?:=[^,]+)?(,\\s*|)/self.$1$2 = $1${3:+\n\t\t}/g}",
			"\t\t$0"
		],
		"description": 'Code snippet for a class definition.'
	}

Screenshot_20231221_213646

Szumak75 avatar Dec 21 '23 20:12 Szumak75

Looking good !

pchoisel avatar Jan 04 '24 11:01 pchoisel