{"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":2,"created_at":"2016-01-08T12:11:59Z","updated_at":"2016-01-08T12:38:16Z","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/169987451","html_url":"https://github.com/JukkaL/mypy/issues/1103#issuecomment-169987451","issue_url":"https://api.github.com/repos/JukkaL/mypy/issues/1103","id":169987451,"user":{"login":"JukkaL","id":1107911,"avatar_url":"https://avatars.githubusercontent.com/u/1107911?v=3","gravatar_id":"","url":"https://api.github.com/users/JukkaL","html_url":"https://github.com/JukkaL","followers_url":"https://api.github.com/users/JukkaL/followers","following_url":"https://api.github.com/users/JukkaL/following{/other_user}","gists_url":"https://api.github.com/users/JukkaL/gists{/gist_id}","starred_url":"https://api.github.com/users/JukkaL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JukkaL/subscriptions","organizations_url":"https://api.github.com/users/JukkaL/orgs","repos_url":"https://api.github.com/users/JukkaL/repos","events_url":"https://api.github.com/users/JukkaL/events{/privacy}","received_events_url":"https://api.github.com/users/JukkaL/received_events","type":"User","site_admin":false},"created_at":"2016-01-08T12:38:16Z","updated_at":"2016-01-08T12:38:16Z","body":"Yeah, the problem is that pylint hasn't been updated to support PEP 484. It's probably worth asking pylint developers if they are interested in adding PEP 484 support. `# type:` comments should be semantically significant for static analyzers and checkers that support PEP 484. Perhaps we should add some language to the PEP regarding linters and other static analysis tools that aren't type checkers.\r\n\r\nYou can request pylint to ignore the problem like this:\r\n\r\n```\r\nimport typing # pylint: disable=unused-import\r\n```"}}