Skip to content

Unexpected Indent with Decorators when sending to terminal #18258

@duylamvo-wefox

Description

@duylamvo-wefox

VS Code version

1.61.0

Extension version

v2021.12.1559732655

OS type

macOS

OS version

10.15.7

Python distribution

Anaconda

Python version

3.7.11

Language server

Pylance

Expected behaviour

Select the code with decorator @ -> [Shift + Enter]

The code should be executed properly

Similar to the issue:

Actual behaviour

Start and Ends of block is wrongly sent.
Only end lines with indent, hence -> Unexpected Indent

Steps to reproduce

def task(func):
    def wrapper():
        print("Something is happening before the function is called.")
        func()
        print("Something is happening after the function is called.")
    return wrapper


@task
def do_a() -> dict:
    msg_d = {"msg": "hello world"}
    print(f"I am task_a. I send a message: {msg_d['msg']}")
    return msg_d
    
@task
def do_b(msg_d: dict) -> int:
    msg = msg_d["msg"]
    print(f"I am task_b. I got a message: {msg}")
    n_len = len(msg)
    return n_len


@task
def do_c(msg_d: dict, n_len: int):
    print(f"I am task_c. I got a message: '{msg_d}' with {n_len} words")

def run():
    print(1)

When I select all code and do [shift+enter] -> It shows Unexpected Indent
When I select only a code, the whole block from @task -> end of block -> it shows only return msg_d with indent -> again, Unexpected Indent

The start and end of block is wrongly sent to terminal

Logs

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

Labels

area-terminalbugIssue identified by VS Code Team member as probable bugverification-neededVerification of issue is requestedverifiedVerification succeeded

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions