a = 'this'
b = 'that'
if a == 'this':
print(f"a is {a}")
else:
with open('/path/to/str.txt', 'r') as f: # content of /path/to/str.txt is a string that can be split e.g. 'test/test/test'
raw = f.read()
string = raw.split('/')[-1]
select the indented code chunk
with open('/path/to/str.txt', 'r') as f: # content of /path/to/str.txt is a string that can be split e.g. 'test/test/test'
raw = f.read()
string = raw.split('/')[-1]
and run it by pressing CTRL + Shift
Returns an indentation error:
string = raw.split('/')[-1]
^
IndentationError: unindent does not match any outer indentation level
Proper handling of indentation like other code editors (e.g. Spyder), where no indentation error occurs (see below)

There is no indentation error in the chunk of code run. This is about how vs code (or the python extension) deals with it
_Please provide as much info as you readily know_
Submitted initial the bug report to repo microsoft/vscode (https://github.com/microsoft/vscode/issues/102672#issuecomment-659740919) and the issue was flagged as being a bug from the python extension
TMScopeRegistry.ts:45 Overwriting grammar scope name to file mapping for scope source.yaml.
Old grammar file: file:///usr/share/code/resources/app/extensions/yaml/syntaxes/yaml.tmLanguage.json.
New grammar file: file:///home/bhinckel/.vscode/extensions/redhat.vscode-yaml-0.9.1/syntaxes/yaml.tmLanguage.json
register @ TMScopeRegistry.ts:45
notebookCellList.ts:783 List with id 'list_id_2' was styled with a non-opaque background color. This will break sub-pixel antialiasing.
style @ notebookCellList.ts:783
console.ts:137 [Extension Host] (node:14428) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
t.log @ console.ts:137
console.ts:137 [Extension Host] (node:14428) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
t.log @ console.ts:137
notificationsAlerts.ts:40 Cannot open resource with notebook editor type 'jupyter-notebook', please check if you have the right extension installed or enabled.
onDidChangeNotification @ notificationsAlerts.ts:40
viewLine.ts:418 monospace assumptions have been violated, therefore disabling monospace optimizations!
monospaceAssumptionsAreValid @ viewLine.ts:418
console.ts:137 [Extension Host] Starting WebSocket: RAW/api/kernels/96ebf62a-ad1f-450e-a5ee-93fd3d16641f
console.ts:137 [Extension Host] Kernel: connected (96ebf62a-ad1f-450e-a5ee-93fd3d16641f)
console.ts:137 [Extension Host] Starting WebSocket: RAW/api/kernels/3e9506e3-3b7e-42ec-8bf1-d2bbbf97a869
console.ts:137 [Extension Host] Kernel: connected (3e9506e3-3b7e-42ec-8bf1-d2bbbf97a869)
webviewElement.ts:160 [Embedded Page] Starting WebSocket: BOGUS_PVSC/api/kernels/96ebf62a-ad1f-450e-a5ee-93fd3d16641f
webviewElement.ts:160 [Embedded Page] Kernel: connected (96ebf62a-ad1f-450e-a5ee-93fd3d16641f)
webviewElement.ts:160 [Embedded Page] Could not create web worker(s). Falling back to loading web worker code in main thread, which might cause UI freezes. Please see https://github.com/Microsoft/monaco-editor#faq
webviewElement.ts:160 [Embedded Page] Failed to construct 'Worker': Script at 'vscode-webview-resource://4792616b-3248-4a76-95f3-f013bd6e44a4/file///home/bhinckel/Desktop/editor.worker.js' cannot be accessed from origin 'vscode-webview://4792616b-3248-4a76-95f3-f013bd6e44a4'.
Microsoft Data Science for VS Code Engineering Team: @rchiodo, @IanMatthewHuff, @DavidKutu, @DonJayamanne, @greazer, @joyceerhl
Thanks for reporting this! I was able to reproduce this behavior. We'll discuss this at our upcoming triage.
@BCArg, Looks like if you select the entire first line (not skip the first indent of the first line), then the behavior works as you expect. We don't have plans on addressing this in the near future. But we'll leave it open for other users to vote on.
Thanks for the reply. It does help a lot already