autopep8 icon indicating copy to clipboard operation
autopep8 copied to clipboard

Fixing use of explicit type comparison to use of isinstance is not reported in verbose output

Open eli-b opened this issue 7 years ago • 5 comments

When using -a, type(a) == foo is fixed to isinstance(a, foo), but this action is not reported in -vvvvv output. As a result, I don't what know what E or W number to use to turn this behavior off.

eli-b avatar May 21 '17 10:05 eli-b

This is probably the lib2to3-based fixer, which I think is in W690.

myint avatar May 21 '17 13:05 myint

Thanks.

Shouldn't -vvvvv at least say that it's running a lib2to3 fixer for W690?

eli-b avatar May 21 '17 13:05 eli-b

That would make sense. I'm not sure why it doesn't.

myint avatar May 21 '17 13:05 myint

When not using -a, the tool revealed that it wants to fix issue E721 on that line. So it's unrelated to lib2to3.

eli-b avatar May 21 '17 16:05 eli-b

$ cat ~/ins.py
a = "a"
foo = 1
type(a) == foo
$ 2to3 -f all -f idioms ins.py
RefactoringTool: Skipping implicit fixer: buffer
RefactoringTool: Skipping implicit fixer: set_literal
RefactoringTool: Skipping implicit fixer: ws_comma
RefactoringTool: Refactored ins.py
--- ins.py	(original)
+++ ins.py	(refactored)
@@ -1,3 +1,3 @@
 a = "a"
 foo = 1
-type(a) == foo
+isinstance(a, foo)
RefactoringTool: Files that need to be modified:
RefactoringTool: ins.py

E721 is global fixer with lib2to3. https://github.com/hhatto/autopep8/blob/master/autopep8.py#L103

hhatto avatar Oct 10 '17 06:10 hhatto