{"action":"created","issue":{"url":"https://api.github.com/repos/JukkaL/mypy/issues/1103","labels_url":"https://api.github.com/repos/JukkaL/mypy/issues/1103/labels{/name}","comments_url":"https://api.github.com/repos/JukkaL/mypy/issues/1103/comments","events_url":"https://api.github.com/repos/JukkaL/mypy/issues/1103/events","html_url":"https://github.com/JukkaL/mypy/issues/1103","id":125600412,"number":1103,"title":"mypy claims that typed code is always still perfectly good ordinary python, but that is not always the case","user":{"login":"mbdevpl","id":1270332,"avatar_url":"https://avatars.githubusercontent.com/u/1270332?v=3","gravatar_id":"","url":"https://api.github.com/users/mbdevpl","html_url":"https://github.com/mbdevpl","followers_url":"https://api.github.com/users/mbdevpl/followers","following_url":"https://api.github.com/users/mbdevpl/following{/other_user}","gists_url":"https://api.github.com/users/mbdevpl/gists{/gist_id}","starred_url":"https://api.github.com/users/mbdevpl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbdevpl/subscriptions","organizations_url":"https://api.github.com/users/mbdevpl/orgs","repos_url":"https://api.github.com/users/mbdevpl/repos","events_url":"https://api.github.com/users/mbdevpl/events{/privacy}","received_events_url":"https://api.github.com/users/mbdevpl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-08T12:11:59Z","updated_at":"2016-01-08T12:54:18Z","closed_at":null,"body":"First of all, I've recently started to annotate my code, and mypy is very helpful in many cases. But I have also found a case where it is not very helpful. Below is a minimal example.\r\n\r\nLet's say I have a file `foo_module.py`:\r\n\r\n```python\r\n\"\"\"\r\n    Module for class Foo.\r\n\"\"\"\r\n\r\nimport typing\r\n\r\nclass Foo:\r\n    \"\"\" Class Foo. \"\"\"\r\n    def __init__(self):\r\n        \"\"\" Constructs fooo. \"\"\"\r\n        self.bars = [] # type: typing.MutableSequence[str]\r\n    def append_bar(self):\r\n        \"\"\" Appends bar to bars. \"\"\"\r\n        self.bars.append('bar')\r\n    def clear_bars(self):\r\n        \"\"\" Clears bars. \"\"\"\r\n        self.bars.clear()\r\n\r\nif __name__ == '__main__':\r\n    FOO = Foo()\r\n    FOO.bars.append(0) # mypy should detect this\r\n```\r\n\r\nIn the above code, I either get \"unused import\" warning from most static analysis tools (e.g. `pylint`), or if I actually comment out the first line, to fix the issue, then, in `mypy` I get \"error: Name 'typing' is not defined\". I cannot say I want to please everyone, but I just want to avoid being mislead by my code analysis tools.\r\n\r\nSpecifically:\r\n\r\n(1) With `import typing` intact:\r\n\r\nPart of output of `pylint foo_module.py`, misleading:\r\n```\r\n************* Module foo_module\r\nW:  5, 0: Unused import typing (unused-import)\r\n```\r\n\r\nOutput from `mypy foo_module.py`, helpful:\r\n```\r\nfoo_module.py:21: error: Argument 1 to \"append\" of \"MutableSequence\" has incompatible type \"int\"; expected \"str\"\r\n```\r\n\r\n(2) With `import typing` as comment:\r\n\r\nNo errors/warnings/etc. from `pylint foo_module.py`, rating 10/10.\r\n\r\nOutput of `mypy foo_module.py`, not very helpful:\r\n```\r\nfoo_module.py: note: In function \"__init__\":\r\nfoo_module.py:11: error: Name 'typing' is not defined\r\n```\r\n... and no information about this bad behaviour in line 21\r\n\r\nIs there any good solution for this?"},"comment":{"url":"https://api.github.com/repos/JukkaL/mypy/issues/comments/169992750","html_url":"https://github.com/JukkaL/mypy/issues/1103#issuecomment-169992750","issue_url":"https://api.github.com/repos/JukkaL/mypy/issues/1103","id":169992750,"user":{"login":"mbdevpl","id":1270332,"avatar_url":"https://avatars.githubusercontent.com/u/1270332?v=3","gravatar_id":"","url":"https://api.github.com/users/mbdevpl","html_url":"https://github.com/mbdevpl","followers_url":"https://api.github.com/users/mbdevpl/followers","following_url":"https://api.github.com/users/mbdevpl/following{/other_user}","gists_url":"https://api.github.com/users/mbdevpl/gists{/gist_id}","starred_url":"https://api.github.com/users/mbdevpl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbdevpl/subscriptions","organizations_url":"https://api.github.com/users/mbdevpl/orgs","repos_url":"https://api.github.com/users/mbdevpl/repos","events_url":"https://api.github.com/users/mbdevpl/events{/privacy}","received_events_url":"https://api.github.com/users/mbdevpl/received_events","type":"User","site_admin":false},"created_at":"2016-01-08T12:54:18Z","updated_at":"2016-01-08T12:54:18Z","body":"Thank you very much for your quick reply! Yes, indeed such pylint request will silence the warning. It seems I need to do more reading on my side. I didn't realize that type comments were not only in mypy, but also part of the PEP.\r\n\r\nI will ask pylint developers about that issue. In the long run I would like to avoid interfering with pylint's work, because the original code is much more complex, and if some type comments are later changed, I would like pylint to notice that some import really is not used anymore.\r\n\r\nKeep up the good work :) Looking forward to non-dev release of mypy :)"}}