Please consider the following example, which finds the first String in a list that contains the Substring "OH":
list = ["STEVE", "JOHN", "YOANN"]
pattern = re.compile(".*%s.*" % "OH")
word = ""
if any((match := pattern.match(item)) for item in list):
word = match.group(0)
print(word)
The code works as intended and outputs "JOHN", but I am getting the following warning from flake8 at the line word = match.group(0)
:
F821 -- undefined name 'match'
Why is this happening, and can I remove the warning without command line arguments or disabling all F821 errors?
flake8 --disable-noqa
orflake8 --ignore=F821
should work. – Leeryflake8
are you using? – CentrumPython3.8
. So either you have to wait until the feature introduced or change the code to use old-style or manually ignore those statements. – Leerynoqa: F821
next to the line?word = match.group(0) # noqa: F821
? like so – Henn