{"action":"created","issue":{"url":"https://api.github.com/repos/python/mypy/issues/3438","repository_url":"https://api.github.com/repos/python/mypy","labels_url":"https://api.github.com/repos/python/mypy/issues/3438/labels{/name}","comments_url":"https://api.github.com/repos/python/mypy/issues/3438/comments","events_url":"https://api.github.com/repos/python/mypy/issues/3438/events","html_url":"https://github.com/python/mypy/issues/3438","id":231008930,"number":3438,"title":"Type variable return value from class methods","user":{"login":"orenbenkiki","id":68190,"avatar_url":"https://avatars2.githubusercontent.com/u/68190?v=3","gravatar_id":"","url":"https://api.github.com/users/orenbenkiki","html_url":"https://github.com/orenbenkiki","followers_url":"https://api.github.com/users/orenbenkiki/followers","following_url":"https://api.github.com/users/orenbenkiki/following{/other_user}","gists_url":"https://api.github.com/users/orenbenkiki/gists{/gist_id}","starred_url":"https://api.github.com/users/orenbenkiki/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orenbenkiki/subscriptions","organizations_url":"https://api.github.com/users/orenbenkiki/orgs","repos_url":"https://api.github.com/users/orenbenkiki/repos","events_url":"https://api.github.com/users/orenbenkiki/events{/privacy}","received_events_url":"https://api.github.com/users/orenbenkiki/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2017-05-24T11:32:51Z","updated_at":"2017-05-24T20:34:59Z","closed_at":null,"body":"`mypy` gets confused about the type of a type variable return value from a class method:\r\n\r\n```python\r\n\r\nfrom typing import TypeVar\r\nfrom typing import Generic\r\n\r\nP=TypeVar('P')\r\n\r\nclass G(Generic[P]):\r\n\r\n    @classmethod\r\n    def c(cls) -> 'P':\r\n        assert False\r\n\r\n    def s(self) -> 'P':\r\n        assert False\r\n\r\nclass C:\r\n    pass\r\n\r\nclass GC(G[C]):\r\n    pass\r\n\r\nc = C()\r\nc = GC().s() # OK\r\nc = GC.c() # error: Incompatible types in assignment (expression has type \"P\", variable has type \"C\")\r\n```\r\n\r\nThis is causing a huge PITA in my code...\r\n\r\nActually, in my code I would *really* want to make `c` a `@classproperty`, that is, be able to write `GC.c` instead of `GC.c()`. I can implement a `@classproperty` decorator by myself, of course, but that would mean giving up on any hope whatsoever of `mypy` being able to type-check my code. Of course, in an ideal world, one would just be able to say both `@property` and `@classmethod`, but they don't compose... Sigh.\r\n\r\nI expected the simple `@classmethod` to work, though. I _assume_ this is a bug? Is there a workaround?\r\n\r\nBTW - I am using `mypy` 0.501 and Python 3.6.0, if that matters..."},"comment":{"url":"https://api.github.com/repos/python/mypy/issues/comments/303843762","html_url":"https://github.com/python/mypy/issues/3438#issuecomment-303843762","issue_url":"https://api.github.com/repos/python/mypy/issues/3438","id":303843762,"user":{"login":"gvanrossum","id":2894642,"avatar_url":"https://avatars0.githubusercontent.com/u/2894642?v=3","gravatar_id":"","url":"https://api.github.com/users/gvanrossum","html_url":"https://github.com/gvanrossum","followers_url":"https://api.github.com/users/gvanrossum/followers","following_url":"https://api.github.com/users/gvanrossum/following{/other_user}","gists_url":"https://api.github.com/users/gvanrossum/gists{/gist_id}","starred_url":"https://api.github.com/users/gvanrossum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gvanrossum/subscriptions","organizations_url":"https://api.github.com/users/gvanrossum/orgs","repos_url":"https://api.github.com/users/gvanrossum/repos","events_url":"https://api.github.com/users/gvanrossum/events{/privacy}","received_events_url":"https://api.github.com/users/gvanrossum/received_events","type":"User","site_admin":false},"created_at":"2017-05-24T20:34:59Z","updated_at":"2017-05-24T20:34:59Z","body":"@orenbenkiki You might want to tone down your language a bit."}}
{"actor":{"display_login":"gvanrossum"}}