{"action":"created","issue":{"url":"https://api.github.com/repos/PyCQA/pep8/issues/398","repository_url":"https://api.github.com/repos/PyCQA/pep8","labels_url":"https://api.github.com/repos/PyCQA/pep8/issues/398/labels{/name}","comments_url":"https://api.github.com/repos/PyCQA/pep8/issues/398/comments","events_url":"https://api.github.com/repos/PyCQA/pep8/issues/398/events","html_url":"https://github.com/PyCQA/pep8/issues/398","id":65394865,"number":398,"title":"E402 False triggers?","user":{"login":"s0undt3ch","id":300048,"avatar_url":"https://avatars.githubusercontent.com/u/300048?v=3","gravatar_id":"","url":"https://api.github.com/users/s0undt3ch","html_url":"https://github.com/s0undt3ch","followers_url":"https://api.github.com/users/s0undt3ch/followers","following_url":"https://api.github.com/users/s0undt3ch/following{/other_user}","gists_url":"https://api.github.com/users/s0undt3ch/gists{/gist_id}","starred_url":"https://api.github.com/users/s0undt3ch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/s0undt3ch/subscriptions","organizations_url":"https://api.github.com/users/s0undt3ch/orgs","repos_url":"https://api.github.com/users/s0undt3ch/repos","events_url":"https://api.github.com/users/s0undt3ch/events{/privacy}","received_events_url":"https://api.github.com/users/s0undt3ch/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-31T08:14:31Z","updated_at":"2016-02-17T04:10:27Z","closed_at":null,"body":"Consider the following snippet:\r\n\r\n```python\r\n# -*- coding: utf-8 -*-\r\n'''\r\nRoutines to set up a minion\r\n'''\r\n# Import python libs\r\nfrom __future__ import absolute_import, print_function\r\nimport os\r\nimport re\r\nimport sys\r\nimport copy\r\nimport time\r\nimport errno\r\nimport types\r\nimport signal\r\nimport fnmatch\r\nimport hashlib\r\nimport logging\r\nimport threading\r\nimport traceback\r\nimport multiprocessing\r\nfrom random import randint, shuffle\r\n\r\n# Import Salt Libs\r\n# pylint: disable=import-error,no-name-in-module,redefined-builtin\r\nimport salt.ext.six as six\r\nfrom salt.ext.six.moves import range\r\n# pylint: enable=no-name-in-module,redefined-builtin\r\n\r\n# Import third party libs\r\ntry:\r\n    import zmq\r\n    HAS_ZMQ = True\r\nexcept ImportError:\r\n    # Running in local, zmq not needed\r\n    HAS_ZMQ = False\r\n\r\nHAS_RANGE = False\r\ntry:\r\n    import seco.range\r\n    HAS_RANGE = True\r\nexcept ImportError:\r\n    pass\r\n\r\nHAS_PSUTIL = False\r\ntry:\r\n    import psutil\r\n    HAS_PSUTIL = True\r\nexcept ImportError:\r\n    pass\r\n\r\nHAS_RESOURCE = False\r\ntry:\r\n    import resource\r\n    HAS_RESOURCE = True\r\nexcept ImportError:\r\n    pass\r\n\r\ntry:\r\n    import zmq.utils.monitor\r\n    HAS_ZMQ_MONITOR = True\r\nexcept ImportError:\r\n    HAS_ZMQ_MONITOR = False\r\n# pylint: enable=import-error\r\n\r\n# Import salt libs\r\nimport salt\r\nimport salt.client\r\nimport salt.crypt\r\n```\r\n\r\nPEP8 reports:\r\n```\r\n❯ pep8 salt/minion.py\r\nsalt/minion.py:66:1: E402 module level import not at top of file\r\nsalt/minion.py:67:1: E402 module level import not at top of file\r\nsalt/minion.py:68:1: E402 module level import not at top of file\r\n```\r\n\r\nWe're still at the \"top import section\" although we're importing our lib as the last imports.\r\nSo my question, is this a false positive? Or pep8 expects to have all imports, not wrapped in a try/except be done first?"},"comment":{"url":"https://api.github.com/repos/PyCQA/pep8/issues/comments/185008879","html_url":"https://github.com/PyCQA/pep8/issues/398#issuecomment-185008879","issue_url":"https://api.github.com/repos/PyCQA/pep8/issues/398","id":185008879,"user":{"login":"IanLee1521","id":828452,"avatar_url":"https://avatars.githubusercontent.com/u/828452?v=3","gravatar_id":"","url":"https://api.github.com/users/IanLee1521","html_url":"https://github.com/IanLee1521","followers_url":"https://api.github.com/users/IanLee1521/followers","following_url":"https://api.github.com/users/IanLee1521/following{/other_user}","gists_url":"https://api.github.com/users/IanLee1521/gists{/gist_id}","starred_url":"https://api.github.com/users/IanLee1521/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IanLee1521/subscriptions","organizations_url":"https://api.github.com/users/IanLee1521/orgs","repos_url":"https://api.github.com/users/IanLee1521/repos","events_url":"https://api.github.com/users/IanLee1521/events{/privacy}","received_events_url":"https://api.github.com/users/IanLee1521/received_events","type":"User","site_admin":false},"created_at":"2016-02-17T04:10:27Z","updated_at":"2016-02-17T04:10:27Z","body":"Agreed with @jayvdb and @sigmavirus24, I'm going to go ahead and close this, as it *is* valid to complain about your `HAS_* = False` lines in the top level."}}