SOLVED: code inspection of modules imported in try/except
Is there some way to get PyCharm to inspect modules which are imported via try/except?
I was reading through another thread which makes mention of using docstrings or some asserts to get the autocompletion to work within the scope of that function/class. I thought perhaps these ideas could be applied here. If so, I'm not able to figure out how.
I was thinking of something along these lines...
Clearly, this doesn't actually work but I hope you get the idea. Doing this...
So is there something like this that I can do to get inspection to work when the module has been wrapped in a try/except?
(I'm even willing to hear suggestions in code changes, provided I'm still able to wrap the import in some sort of try/except)
try: import sys except ImportError: sys = None def foo(): sys.exit() # <-- does not inspect sys.exit() # <-- inspects
I was reading through another thread which makes mention of using docstrings or some asserts to get the autocompletion to work within the scope of that function/class. I thought perhaps these ideas could be applied here. If so, I'm not able to figure out how.
I was thinking of something along these lines...
def foo(): assert isinstance(sys, sys) sys.exit()
Clearly, this doesn't actually work but I hope you get the idea. Doing this...
isinstance(sys, types.ModuleType)proves the variable is a module, but doesn't seem to have an affect on Pycharm's inspection (not that I expected it would).
So is there something like this that I can do to get inspection to work when the module has been wrapped in a try/except?
(I'm even willing to hear suggestions in code changes, provided I'm still able to wrap the import in some sort of try/except)
1 comment
Sort by
Date
Votes
A coworker pointed out my code sample code works fine in 2.6.2.
Please sign in to leave a comment.