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

profile # throws an exception when profile isn't defined
except NameError:
profile = identity # if it's not defined simply ignore the decorator.

Comment actions Permalink

You can disable it in **File | Settings | Editor | Inspections > Python > Unbound local variable**

Comment actions Permalink

That disables it everywhere, I wondering if there's a way to disable it for that line only.


Please sign in to leave a comment.