Open samueljsb opened 10 months ago
I've found another one that's causing us problems: decorators.
from dataclasses import dataclass
@dataclass()
class C:
pass
# lint-fixme: ExplicitFrozenDataclass
@dataclass()
class C:
pass
@dataclass() # lint-fixme: ExplicitFrozenDataclass
class C:
pass
We'd expect the first function to be reported, and the other two to be silenced.
t.py@4:0 ExplicitFrozenDataclass: When using dataclasses, explicitly specify a frozen keyword argument. Example: `@dataclass(frozen=True)` or `@dataclass(frozen=False)`. Docs: https://docs.python.org/3/library/dataclasses.html (has autofix)
t.py@10:0 ExplicitFrozenDataclass: When using dataclasses, explicitly specify a frozen keyword argument. Example: `@dataclass(frozen=True)` or `@dataclass(frozen=False)`. Docs: https://docs.python.org/3/library/dataclasses.html (has autofix)
๐ ๏ธ 1 file checked, 1 file with errors, 2 auto-fixes available ๐ ๏ธ
But we see the first two reported. The last one is correctly silenced.
I have written some failing tests to demonstrate these problems in #413. I haven't worked out how to demonstrate the function def problem yet, so I'd appreciate any advice you can offer there.
I have found another case. This looks superficially similar to the comprehensions case.
In the following file (t.py
), we would expect the violation to be reported for the first function, but not for either of the other two.
def f(x):
return (
isinstance(x, int) or isinstance(x, float)
)
def f(x):
return (
isinstance(x, int) or isinstance(x, float) # lint-fixme: CollapseIsinstanceChecks
)
def f(x):
return (
# lint-fixme: CollapseIsinstanceChecks
isinstance(x, int) or isinstance(x, float)
)
However, the violation is reported for all three:
$ fixit lint t.py
t.py@3:8 CollapseIsinstanceChecks: Multiple isinstance calls with the same target but different types can be collapsed into a single call with a tuple of types. (has autofix)
t.py@9:8 CollapseIsinstanceChecks: Multiple isinstance calls with the same target but different types can be collapsed into a single call with a tuple of types. (has autofix)
t.py@16:8 CollapseIsinstanceChecks: Multiple isinstance calls with the same target but different types can be collapsed into a single call with a tuple of types. (has autofix)
๐ ๏ธ 1 file checked, 1 file with errors, 3 auto-fixes available ๐ ๏ธ
lint-fixme
comments on nodes in some cases are not respected.comprehensions
In the following file (
t.py
), we would expect the violation to be reported for the first function, but not for either of the other two.However, the violation is reported for all three:
lambdas
In the following file (
t.py
), we would expect the violation to be reported for the first list, but not for either of the other two.However, the violation is reported for all three:
EDIT: the commit is respected if it is placed before the list:
This is not expected, though, and means that multiple lines will be ignored rather than just the desired one.
methods
In the following file (
t.py
), we would expect the violation to be reported for the first class, but not for either of the other two.However, the violation is correctly silenced for the last case, but shown for the middle case that should be silenced:
supporting information
I have also observed this behaviour on Python 3.10.11.