abarker / camel-snake-pep8

Use Rope to help convert names in a Python project to conform with PEP-8.
MIT License
49 stars 4 forks source link

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

Open HWiese1980 opened 2 years ago

HWiese1980 commented 2 years ago

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 commented 2 years ago

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

HWiese1980 commented 2 years ago

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 commented 2 years ago

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.

abarker commented 2 years ago

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.

nj-kore commented 1 year ago

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

abarker commented 1 year ago

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