pylint icon indicating copy to clipboard operation
pylint copied to clipboard

False positive `deprecated-class` when the class is imported in a guarded import block

Open perrinjerome opened this issue 1 year ago • 0 comments

Current problem

import sys

if sys.version_info > (2, ):
    from collections.abc import Set
else:
    from collections import Set

isinstance(set(), Set)
$ pylint --disable=C a.py
************* Module a
a.py:6:4: W4904: Using deprecated class Set of module collections (deprecated-class)

-----------------------------------
Your code has been rated at 8.00/10

Desired solution

In https://github.com/pylint-dev/pylint/pull/4702 pylint was extended with a concept of "guarded import blocks" and it does not trigger import-error and similar errosr when the import is made in a guarded import block.

I believe it would be nice to have same behavior for deprecated-class as well.

Additional context

No response

perrinjerome avatar Apr 03 '24 05:04 perrinjerome