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?