Disable "Unbound local variable" inspection locally?
Is there a way to disable it locally?
I'm using the following block to allow me to use "@profile" decorators which are only defined when running under line profiler (kernprof -l script.py)
I'd like to disable the warning on "profile" inside the "try/except", since I'm handling the UnboundLocal error in the code
# for line profiling
def identity(x):
return x
try:
profile # throws an exception when profile isn't defined
except NameError:
profile = identity # if it's not defined simply ignore the decorator.
Please sign in to leave a comment.
You can disable it in **File | Settings | Editor | Inspections > Python > Unbound local variable**
That disables it everywhere, I wondering if there's a way to disable it for that line only.
Yes, you can suppress inspections: https://www.jetbrains.com/help/pycharm/disabling-and-enabling-inspections.html#suppress-inspections
Also, using special comments: https://www.jetbrains.com/help/pycharm/disabling-and-enabling-inspections.html#suppressing-comments