"Run Selection" does not handle decorators properly.
See original GitHub issuedef my_decorator(func):
def wrapper():
print("Something is happening before the function is called.")
func()
print("Something is happening after the function is called.")
return wrapper
@my_decorator
def say_whee():
print("Whee!")
say_whee()
shift+enter or ‘run’ button in vscode
>>> def my_decorator(func):
... def wrapper():
... print("Something is happening before the function is called.")
... func()
... print("Something is happening after the function is called.")
... return wrapper
... @my_decorator
File "<stdin>", line 7
@my_decorator
^
SyntaxError: invalid syntax
>>>
>>> def say_whee():
... print("Whee!")
...
>>> say_whee()
Whee!
>>>
python extension v2021.1.442908725-dev
Issue Analytics
- State:
- Created 3 years ago
- Reactions:12
- Comments:24 (7 by maintainers)
Top Results From Across the Web
Simple decorator does not work with Python multiprocessing
I have built a simple decorator that tracks if the function has been run or not. import functools from multiprocessing import Process, ...
Read more >Primer on Python Decorators
In this introductory tutorial, we'll look at what Python decorators are and how to create and use them.
Read more >Decorators - Python 3 Patterns, Recipes and Idioms
The only constraint on the result of a decorator is that it be callable, so it can properly replace the decorated function. In...
Read more >Understanding Python Decorators - Techblog
We look at how python decorators work using an example from the python decorator library - one which retries function execution on failure....
Read more >Decorators - Storybook - JS.ORG
A decorator is a way to wrap a story in extra “rendering” functionality. Many addons define decorators to augment your stories with extra...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Verification steps:
Run Selection/Line in Terminal
commandWhat appears to be happening is the following:
Ways of executing code with decorators that do seem to be working normally are:
python [script-path]
Hence it is only the top level decorators that don’t work with “Python: Run Selection/Line in Python Terminal” (shift + enter) and it seems to be because the lines get evaluated / executed in isolation if they are not part of some indented block or pasted in as a whole. If “Python: Run Selection/Line in Python Terminal” (shift + enter) could be made to work like pasting from the clipboard works, then the problem would be solved.