camel-snake-pep8 icon indicating copy to clipboard operation
camel-snake-pep8 copied to clipboard

It wants to rename `Exception` to `exception` and ends up in an infinite loop if I tell it `no`.

Open HWiese1980 opened this issue 2 years ago • 6 comments

There are sections in a code base I'm currently cleaning up which simply do

raise Exception("foobar")

or

try:
    ...
except Exception:
    ...

camel-snake-pep8 wants to rename Exception here to exception which is syntactically wrong.

Types should be excluded from being renamed, as PEP8 recommends them to be camel case

HWiese1980 avatar Jul 28 '22 11:07 HWiese1980

Oh and when I select "no" it ends up in a loop.

HWiese1980 avatar Jul 28 '22 12:07 HWiese1980

Okay, I've figured out that it's got something to do with using loguru.

A loguru logger has a method called exception which is muddled up by either Rope or camel-snake-pep8 with the builtin Exception class.

Investigating...

HWiese1980 avatar Jul 28 '22 12:07 HWiese1980

This is really weird. For some reason in one of my programs the Rope Worder seems to detect the builtin Exception type as coming from loguru. As mentioned, there is a method exception (with a small letter e) in the loguru logger. I've tried to reproduce this error by building a small example program that utilizes loguru but I wasn't able to reproduce it. The small program gets refactored as expected. There must be something else interfering with camel-snake-pep8 or rope...

I've given up. Unfortunately, I can't continue using camel-snake-pep8 because of the loop bug. When I tell it not to rename Exception to exception it ends up in an endless loop because it re-detects the potential renaming of Exception.

HWiese1980 avatar Jul 29 '22 18:07 HWiese1980

I tried a small example based on your description above and I couldn't reproduce the problem either. As a possible workaround, if there are only one or two places where that kind of error occurs you could temporarily comment-out that code or rename to something like ExceptionXXXX while you convert the other variables.

abarker avatar Jul 29 '22 19:07 abarker

I now get the exact same problem but with changing False to false

nj-kore avatar Nov 25 '22 17:11 nj-kore

@nj-kore, do you have a code snippet which reproduces the problem?

abarker avatar Nov 25 '22 18:11 abarker