Error: Statement expected, found py: Dedent

My problem was caused by indentation mismatch. Most of the document was indented with spaces but there were some tabs copied in that caused the Py:DEDENT error. Replacing the tabs with spaces fixed the error.


If you face this issue in PyCharm 2021.2 add the following line

-ea

to Help | Edit Custom VM Options ... or to <PyCharm_installation_folder>/bin/pycharm.vmoptions (or pycharm64.vmoptions). Restart PyCharm and the parser should work correctly.

See the relevant ticket in PyCharm's bug tracker https://youtrack.jetbrains.com/issue/PY-49970


Update: the fix is available in 2021.2.1 RC.


Problem solved by ignoring the error. Copied to an other editor and nothing here. So seems to be a PyCharm mistake.