We are willing/ forced to develop a small Web App for the university. Now we started and everything seems to be fine, until the above strange error raises.
Statement expected, found py: Dedent
The error is raised by the following lines of code:
def get_reset_token(self, mysql, userid):
try:
conn = mysql.connect()
cursor = conn.cursor()
cursor.execute("""SELECT token FROM tralala_reset_password
WHERE uid=(%s)""", userid)
data = cursor.fetchall()
cursor.close()
conn.close()
return data[0]
except Exception as e:
app.logger(str(e))
return ""
PyCharm started to mark the return ""
statement.
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.
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.
I was also scratching my head for significant period of time and finally figured it out.
The thing is outside of "pycharm did not recognize certain char" scope
When you write this:
class Foo:
def complicated_method(self):
for f to self.whatever:
# plenty of code goes here
pass
def another one():
# here too
pass
And then you decide to rewrite it:
class Foo:
def complicated_method(self):
# plenty of code goes here <- mistakenly leaved unindented, many unseen errors here
pass
def another one(self):
# here too
pass
....
def do(self):
for f in self.whatever:
self.complicated_method() <- here will be Py:DEDENT
Refactor long methods, if you can, and Py:DEDENT
will never bother you again
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With