Home > OS >  Automatically adding a decorator to each Python function in VSCode?
Automatically adding a decorator to each Python function in VSCode?

Time:11-04

While trying to add the @typechecked property above all (of the 487) functions, I was experiencing some difficulties with finding the right replace command. I intend to go from:

    def some_function(

to:

    @typechecked
    def some_function(

However, when I do Ctrl H and replace def with:

@typechecked
def 

The indentation of the def gets lost.

Hence I would like to ask: How can I add the property typechecked above all functions in all .py` files in vscode?

CodePudding user response:

Do a find/replace in VSCode with the following find and replace values:

     find: ^(\s*)(def [\w_] \()
  replace: $1@typechecked\n$1$2

CodePudding user response:

use

Find: ^(\s*)def

Replace: $1@typechecked\n$1def

  • Related