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.

3 comments

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

0

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

0

Please sign in to leave a comment.