{"action":"created","issue":{"url":"https://api.github.com/repos/python/mypy/issues/1561","repository_url":"https://api.github.com/repos/python/mypy","labels_url":"https://api.github.com/repos/python/mypy/issues/1561/labels{/name}","comments_url":"https://api.github.com/repos/python/mypy/issues/1561/comments","events_url":"https://api.github.com/repos/python/mypy/issues/1561/events","html_url":"https://github.com/python/mypy/issues/1561","id":156023536,"number":1561,"title":"Will recursive or mutually recursive bounds on TypeVar be supported?","user":{"login":"smallnamespace","id":15881001,"avatar_url":"https://avatars.githubusercontent.com/u/15881001?v=3","gravatar_id":"","url":"https://api.github.com/users/smallnamespace","html_url":"https://github.com/smallnamespace","followers_url":"https://api.github.com/users/smallnamespace/followers","following_url":"https://api.github.com/users/smallnamespace/following{/other_user}","gists_url":"https://api.github.com/users/smallnamespace/gists{/gist_id}","starred_url":"https://api.github.com/users/smallnamespace/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/smallnamespace/subscriptions","organizations_url":"https://api.github.com/users/smallnamespace/orgs","repos_url":"https://api.github.com/users/smallnamespace/repos","events_url":"https://api.github.com/users/smallnamespace/events{/privacy}","received_events_url":"https://api.github.com/users/smallnamespace/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-05-20T18:28:12Z","updated_at":"2016-05-30T16:26:37Z","closed_at":null,"body":"Reading through the discussion at https://github.com/python/typing/issues/59, there was an example that had `TypeVar` bound that referenced itself. Is this intended to be eventually implemented? The actual PEP just has a bare `Comparable`.\r\n\r\nA motivating example (from the Java world) is discussed [here](http://stackoverflow.com/a/3061776), in the context of their `Enum`. An example in Python:\r\n\r\n```python\r\nfrom typing import Generic, Optional, Tuple, TypeVar  \r\n\r\n# Would like to write bound='TypedCons[T, V]' here, where T is self-referential\r\nT = TypeVar('T', bound='TypedCons')\r\nV = TypeVar('V')  \r\n  \r\n  \r\nclass TypedCons(Generic[T, V]):  \r\n    def __init__(self, value: V, cdr: Optional[T]=None) -> None:  \r\n        self.value = value  \r\n        self.cdr = cdr  \r\n  \r\n    def first_two(self) -> Tuple[T, T]:  \r\n        # Fails without cast with \"Incompatible return value type: expected Tuple[T`1, T`1], got Tuple[example.TypedCons[T`1, V`2], T`1]\"  \r\n        return self, self.cdr  \r\n  \r\nclass IntCons(TypedCons['IntCons', int]):  \r\n    pass\r\n  \r\n# Recursive bound would reject this\r\nclass BadCons(TypedCons['IntCons', str]):  \r\n    pass  \r\n```\r\nIf I try to write the recursive bound, I get:\r\n\r\n`example.py:3: error: Invalid type \"example.T\"`\r\n\r\nA similar example where this is needed is at https://github.com/smallnamespace/pymcts/blob/b5e1375e67983ef7b5baa2511c680074fd31b00c/pymcts/tree.py#L78 -- here we need to use the fact that `N` and `Node` are identical."},"comment":{"url":"https://api.github.com/repos/python/mypy/issues/comments/222524026","html_url":"https://github.com/python/mypy/issues/1561#issuecomment-222524026","issue_url":"https://api.github.com/repos/python/mypy/issues/1561","id":222524026,"user":{"login":"gvanrossum","id":2894642,"avatar_url":"https://avatars.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":"2016-05-30T16:26:37Z","updated_at":"2016-05-30T16:26:37Z","body":"Honestly my head explodes each time I try to understand this idea. So maybe\nit's also hard to implement? OTOH if you can come up with a patch I'm not\nopposed.\n\n--Guido (mobile)\n"}}
{"actor":{"display_login":"gvanrossum"}}