)]}'
{"/COMMIT_MSG":[{"author":{"_account_id":1849,"name":"Joe Gordon","email":"joe.gordon0@gmail.com","username":"jogo"},"change_message_id":"9a6c65a9ce87105adba04c75544576ff0af9d19a","unresolved":false,"context_lines":[{"line_number":4,"context_line":"Commit:     Ivan A. Melnikov \u003cmelnikov@yahoo-inc.com\u003e"},{"line_number":5,"context_line":"CommitDate: 2014-01-28 11:35:54 +0400"},{"line_number":6,"context_line":""},{"line_number":7,"context_line":"More portable way to detect modules for H302"},{"line_number":8,"context_line":""},{"line_number":9,"context_line":"Instead of analysing string representation of import exception we"},{"line_number":10,"context_line":"try harder to import the thing and then look it up in sys.modules"}],"source_content_type":"text/x-gerrit-commit-message","patch_set":3,"id":"AAAAUH%2F9aZg%3D","line":7,"updated":"2014-02-07 03:45:30.000000000","message":"this isn\u0027t for just H302","commit_id":"e90680cff5d6517c5328c7990b9b0d75d18ce272"}],"hacking/core.py":[{"author":{"_account_id":2472,"name":"Doug Hellmann","email":"dhellmann@redhat.com","username":"doug-hellmann"},"change_message_id":"793193d6f6ec38bb6246a9bd28d68170bf3fde4a","unresolved":false,"context_lines":[{"line_number":467,"context_line":"                else:"},{"line_number":468,"context_line":"                    __import__(mod)"},{"line_number":469,"context_line":"            except ImportError:"},{"line_number":470,"context_line":"                # NOTE(imelnikov): the import error must be due to a missing"},{"line_number":471,"context_line":"                # dependency, so we assume the best"},{"line_number":472,"context_line":"                return True"},{"line_number":473,"context_line":"            except Exception:"}],"source_content_type":"text/x-python","patch_set":2,"id":"AAAAUH%2F%2BYfE%3D","line":470,"updated":"2014-01-27 14:26:56.000000000","message":"Is a missing dependency really the only reason an ImportError might be thrown? The previous iteration was looking at the exception\u0027s message. Maybe we just need to look for some other substrings?","commit_id":"f1e52c4f0ad60b773f34c5b44ef532fc3140e406"},{"author":{"_account_id":7366,"name":"Ivan Melnikov","email":"imelnikov@griddynamics.com","username":"imelnikov"},"change_message_id":"3be5e2bf729fa99d2811ecd32ec02706dfdac772","unresolved":false,"context_lines":[{"line_number":467,"context_line":"                else:"},{"line_number":468,"context_line":"                    __import__(mod)"},{"line_number":469,"context_line":"            except ImportError:"},{"line_number":470,"context_line":"                # NOTE(imelnikov): the import error must be due to a missing"},{"line_number":471,"context_line":"                # dependency, so we assume the best"},{"line_number":472,"context_line":"                return True"},{"line_number":473,"context_line":"            except Exception:"}],"source_content_type":"text/x-python","patch_set":2,"id":"AAAAUH%2F%2BTaA%3D","line":470,"in_reply_to":"AAAAUH%2F%2BYfE%3D","updated":"2014-01-28 07:30:04.000000000","message":"As far as I understand, __import__(mod) can fail for two reasons: (a) mod is just not there and (b) mod is not a module (e. g. \u0027os.path.dirname\u0027, with original line being \u0027from os.path import dirname\u0027). Previous iteration looked at exception string to distinguish these two cases. My approach is different: try harder to import mod, whatever it is (lines 464-465 above should handle \u0027os.path.dirname\u0027 case properly) and then just check if what was imported is a module (on line 481 below).\n\nSo, unless I\u0027m missing something, ImportError here means mod is just not there. Of course, there might be other reasons for that along with missing dependencies -- like typos or path issues -- but in any case there is no way for us to know if it is module or not.\n\nBut maybe I should update my comment to make it more clear.","commit_id":"f1e52c4f0ad60b773f34c5b44ef532fc3140e406"},{"author":{"_account_id":2472,"name":"Doug Hellmann","email":"dhellmann@redhat.com","username":"doug-hellmann"},"change_message_id":"793193d6f6ec38bb6246a9bd28d68170bf3fde4a","unresolved":false,"context_lines":[{"line_number":478,"context_line":"            else:"},{"line_number":479,"context_line":"                # NOTE(imelnikov): we imported the thing; if it was module,"},{"line_number":480,"context_line":"                # it must be there:"},{"line_number":481,"context_line":"                return mod in sys.modules"},{"line_number":482,"context_line":"        return True"},{"line_number":483,"context_line":""},{"line_number":484,"context_line":"    def is_module(mod):"}],"source_content_type":"text/x-python","patch_set":2,"id":"AAAAUH%2F%2BYfw%3D","line":481,"updated":"2014-01-27 14:26:56.000000000","message":"You could also use inspect.ismodule() to examine mod directly.","commit_id":"f1e52c4f0ad60b773f34c5b44ef532fc3140e406"},{"author":{"_account_id":7366,"name":"Ivan Melnikov","email":"imelnikov@griddynamics.com","username":"imelnikov"},"change_message_id":"3be5e2bf729fa99d2811ecd32ec02706dfdac772","unresolved":false,"context_lines":[{"line_number":478,"context_line":"            else:"},{"line_number":479,"context_line":"                # NOTE(imelnikov): we imported the thing; if it was module,"},{"line_number":480,"context_line":"                # it must be there:"},{"line_number":481,"context_line":"                return mod in sys.modules"},{"line_number":482,"context_line":"        return True"},{"line_number":483,"context_line":""},{"line_number":484,"context_line":"    def is_module(mod):"}],"source_content_type":"text/x-python","patch_set":2,"id":"AAAAUH%2F%2BTZE%3D","line":481,"in_reply_to":"AAAAUH%2F%2BYfw%3D","updated":"2014-01-28 07:30:04.000000000","message":"\u0027mod\u0027 is string here (a fully qualified name), so to use inspect.ismodule() I\u0027d need to get the object it refers to -- either from __import__ output or from somewhere else -- which is not a trivial thing to do. Just looking it up in sys.modules looks a lot simpler and as reliable.","commit_id":"f1e52c4f0ad60b773f34c5b44ef532fc3140e406"}]}
