{"action":"created","issue":{"url":"https://api.github.com/repos/python/mypy/issues/4812","repository_url":"https://api.github.com/repos/python/mypy","labels_url":"https://api.github.com/repos/python/mypy/issues/4812/labels{/name}","comments_url":"https://api.github.com/repos/python/mypy/issues/4812/comments","events_url":"https://api.github.com/repos/python/mypy/issues/4812/events","html_url":"https://github.com/python/mypy/issues/4812","id":309277638,"number":4812,"title":"Several same Forward References in TypedDict wrongly detected as Recusive Type","user":{"login":"Jym77","id":19969498,"avatar_url":"https://avatars3.githubusercontent.com/u/19969498?v=4","gravatar_id":"","url":"https://api.github.com/users/Jym77","html_url":"https://github.com/Jym77","followers_url":"https://api.github.com/users/Jym77/followers","following_url":"https://api.github.com/users/Jym77/following{/other_user}","gists_url":"https://api.github.com/users/Jym77/gists{/gist_id}","starred_url":"https://api.github.com/users/Jym77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jym77/subscriptions","organizations_url":"https://api.github.com/users/Jym77/orgs","repos_url":"https://api.github.com/users/Jym77/repos","events_url":"https://api.github.com/users/Jym77/events{/privacy}","received_events_url":"https://api.github.com/users/Jym77/received_events","type":"User","site_admin":false},"labels":[{"id":21488356,"url":"https://api.github.com/repos/python/mypy/labels/bug","name":"bug","color":"fc2929","default":true},{"id":513232552,"url":"https://api.github.com/repos/python/mypy/labels/priority-1-normal","name":"priority-1-normal","color":"fef2c0","default":false},{"id":488169816,"url":"https://api.github.com/repos/python/mypy/labels/topic-typed-dict","name":"topic-typed-dict","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":{"login":"ilevkivskyi","id":12005495,"avatar_url":"https://avatars1.githubusercontent.com/u/12005495?v=4","gravatar_id":"","url":"https://api.github.com/users/ilevkivskyi","html_url":"https://github.com/ilevkivskyi","followers_url":"https://api.github.com/users/ilevkivskyi/followers","following_url":"https://api.github.com/users/ilevkivskyi/following{/other_user}","gists_url":"https://api.github.com/users/ilevkivskyi/gists{/gist_id}","starred_url":"https://api.github.com/users/ilevkivskyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilevkivskyi/subscriptions","organizations_url":"https://api.github.com/users/ilevkivskyi/orgs","repos_url":"https://api.github.com/users/ilevkivskyi/repos","events_url":"https://api.github.com/users/ilevkivskyi/events{/privacy}","received_events_url":"https://api.github.com/users/ilevkivskyi/received_events","type":"User","site_admin":false},"assignees":[{"login":"ilevkivskyi","id":12005495,"avatar_url":"https://avatars1.githubusercontent.com/u/12005495?v=4","gravatar_id":"","url":"https://api.github.com/users/ilevkivskyi","html_url":"https://github.com/ilevkivskyi","followers_url":"https://api.github.com/users/ilevkivskyi/followers","following_url":"https://api.github.com/users/ilevkivskyi/following{/other_user}","gists_url":"https://api.github.com/users/ilevkivskyi/gists{/gist_id}","starred_url":"https://api.github.com/users/ilevkivskyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilevkivskyi/subscriptions","organizations_url":"https://api.github.com/users/ilevkivskyi/orgs","repos_url":"https://api.github.com/users/ilevkivskyi/repos","events_url":"https://api.github.com/users/ilevkivskyi/events{/privacy}","received_events_url":"https://api.github.com/users/ilevkivskyi/received_events","type":"User","site_admin":false}],"milestone":null,"comments":1,"created_at":"2018-03-28T08:58:26Z","updated_at":"2018-03-28T09:45:14Z","closed_at":null,"author_association":"NONE","body":"MNWE:\r\n```\r\nfrom mypy_extensions import TypedDict\r\nfrom typing import Any, List\r\n\r\nclass Foo(TypedDict):\r\n    bar: 'Bar'\r\n    baz: 'Bar'\r\n\r\n# Foo = TypedDict('Foo', {'bar': 'Bar', 'baz': Bar})\r\n\r\nBar = List[Any]\r\n```\r\n\r\nResult: \r\n```\r\n$ mypy --python-version 3.6 mypy_test.py \r\nmypy_test.py:4: error: Recursive types not fully supported yet, nested types replaced with \"Any\"\r\n```\r\n(Python 3.6, mypy 0.570 & 0.580)\r\n\r\nThe TypedDict Foo has two fields, both being of type Bar which is defined later and a forward reference is used to mention it (obviously not needed in this MWNE but needed in real life). This is incorrectly detected as a Recursive type by mypy which then produce a rather confusing error message.\r\n\r\nThe error appears using both syntaxes for TypedDict (the class-like syntax used here, or the TypedDict() syntax commented out).\r\n\r\nThe error disappears without the forward reference (moving the definition of Bar up and removing the quotes in Foo). The error stays if Bar is moved up and the quote stay in Foo (\"forward\" reference backward?)\r\n\r\nThe error only appears if there are two (or more) fields of type Bar inside Foo. If either bar or baz is removed, the error disappears.\r\n\r\nThe error disappears if Bar is a simpler type, eg int or Any. It seems to depend on a more complex type."},"comment":{"url":"https://api.github.com/repos/python/mypy/issues/comments/376826968","html_url":"https://github.com/python/mypy/issues/4812#issuecomment-376826968","issue_url":"https://api.github.com/repos/python/mypy/issues/4812","id":376826968,"user":{"login":"Jym77","id":19969498,"avatar_url":"https://avatars3.githubusercontent.com/u/19969498?v=4","gravatar_id":"","url":"https://api.github.com/users/Jym77","html_url":"https://github.com/Jym77","followers_url":"https://api.github.com/users/Jym77/followers","following_url":"https://api.github.com/users/Jym77/following{/other_user}","gists_url":"https://api.github.com/users/Jym77/gists{/gist_id}","starred_url":"https://api.github.com/users/Jym77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jym77/subscriptions","organizations_url":"https://api.github.com/users/Jym77/orgs","repos_url":"https://api.github.com/users/Jym77/repos","events_url":"https://api.github.com/users/Jym77/events{/privacy}","received_events_url":"https://api.github.com/users/Jym77/received_events","type":"User","site_admin":false},"created_at":"2018-03-28T09:45:14Z","updated_at":"2018-03-28T09:45:14Z","author_association":"NONE","body":"Same problem (I guess), but even less intuitive:\r\n```\r\nfrom mypy_extensions import TypedDict\r\nfrom typing import Any, List\r\n\r\nBar = List[Any]\r\n\r\nclass Foo(TypedDict):\r\n    foo: 'Toto'\r\n    bar: Bar\r\n    baz: Bar\r\n\r\nToto = int\r\n```\r\nThis causes an incorrect Recursive Types detection.\r\nRemoving any of the fields in Foo makes the Recursive Type detection disappear. Moving Toto up also does that.\r\n\r\nSo it needs both a type being used more than once, and a forward reference, but not necessarily on the same type. And the duplicated type need to be complex enough (`Bar = int` is OK)."}}
{"actor":{"display_login":"Jym77"}}