It seems like the Python Analyzer generates two entries with the same exact feedback when using a tuple for a membership test (instead of a set) inside a generator expression.
My first iteration for the Acronym exercise triggered this bug:
My code
"""Module providing a function that abbreviates phrases."""
def abbreviate(phrase: str) -> str:
"""Returns an abbreviation of the input phrase."""
phrase = ''.join(' ' if char == '-' else char
for char in phrase
if char.isalpha() or char in (' ', '-'))
return ''.join(word[0].upper() for word in phrase.split())
The Analyzer’s feedback:
Analyzer output
Recommended
Line 8 [R6201 use-set-for-membership] was reported by Pylint:
Consider using set for membership test.
This code is emitting a code smell, and may be in need of a re-write or refactor. This doesn’t mean the code is incorrect or buggy in a technical sense, only that it appears to have one or more patterns that could lead to future bugs or maintenance issues. Consider taking a closer look at it.
Instead of:
def fruit_is_dangerous_for_cat(fruit: str) -> bool:
"""This list is only a silly example, don't make decision regarding your cat diet based on it."""
return fruit in ["cherry", "grapes"] # [use-set-for-membership]
Try:
def fruit_is_dangerous_for_cat(fruit: str) -> bool:
"""This list is only a silly example, don't make decision regarding your cat diet based on it."""
return fruit in {"cherry", "grapes"}
Recommended
Line 8 [R6201 use-set-for-membership] was reported by Pylint:
Consider using set for membership test.
This code is emitting a code smell, and may be in need of a re-write or refactor. This doesn’t mean the code is incorrect or buggy in a technical sense, only that it appears to have one or more patterns that could lead to future bugs or maintenance issues. Consider taking a closer look at it.
Instead of:
def fruit_is_dangerous_for_cat(fruit: str) -> bool:
"""This list is only a silly example, don't make decision regarding your cat diet based on it."""
return fruit in ["cherry", "grapes"] # [use-set-for-membership]
Try:
def fruit_is_dangerous_for_cat(fruit: str) -> bool:
"""This list is only a silly example, don't make decision regarding your cat diet based on it."""
return fruit in {"cherry", "grapes"}