`--autofix` doesn't seem to work for `tryceratops>=2.2.0`
kdestin opened this issue · comments
Environment
Operating System: Ubuntu 22.04 (kernel 5.15.0-72-generic)
Tryceratops Version: 2.3.2 (But I've also observed this issue with 2.2.0)
pip list:
Package Version
----------------- -------
click 8.1.3
markdown-it-py 2.2.0
mdurl 0.1.2
pip 20.3.3
Pygments 2.15.1
rich 13.4.1
setuptools 67.6.0
toml 0.10.2
tryceratops 2.3.2
typing-extensions 4.6.2
wheel 0.37.0
Describe the problem
I was trying to use tryceratops
to fix some issues in my codebase. I was specifically interested in fixing TRY200
and noticed that using --autofix
didn't seem to actually do anything.
I was able to reproduce this problem with 2.3.2 and 2.2.0
I was able to confirm that--autofix
was working with versions: 2.0.0, 2.1.0 and 2.1.1
Steps to Reproduce
-
Install tryceratops==2.3.2
-
Prepare file that intentionally violates
TRY200
,TRY201
, andTRY400
. (Taken from the documentation for each of those checks).# Try200 def main_function(): try: process() handle() finish() except Exception: raise MainFunctionFailed() # Try201 try: ... except CustomException as ex: raise ex # Try400 def main_function(): try: process() handle() finish() except Exception as ex: logger.error("Context message here")
-
Run
tryceratops --autofix repro.py
Expected Behavior
$ tryceratops --autofix repro.py
[TRY400] Use logging '.exception' instead of '.error' - repro.py:23:8
[TRY200] Use 'raise from' to specify exception cause - repro.py:8:8
[TRY203] Useless try-except, remove it or handle the exception - repro.py:11:0
[TRY201] Simply use 'raise' without specifying exception object again - repro.py:14:4
Done processing!
Processed 1 files
Found 4 violations
Fixed 3 violations
Actual Behavior
$ tryceratops --autofix repro.py
[TRY203] Useless try-except, remove it or handle the exception - repro.py:11:0
[TRY400] Use logging '.exception' instead of '.error' - repro.py:23:8
[TRY201] Simply use 'raise' without specifying exception object again - repro.py:14:4
[TRY200] Use 'raise from' to specify exception cause - repro.py:8:8
Done processing!
Processed 1 files
Found 4 violations
Note the missing Fixed 3 violations