{"action":"created","issue":{"url":"https://api.github.com/repos/python/mypy/issues/4944","repository_url":"https://api.github.com/repos/python/mypy","labels_url":"https://api.github.com/repos/python/mypy/issues/4944/labels{/name}","comments_url":"https://api.github.com/repos/python/mypy/issues/4944/comments","events_url":"https://api.github.com/repos/python/mypy/issues/4944/events","html_url":"https://github.com/python/mypy/issues/4944","id":316065704,"number":4944,"title":"Take into account the results of dir(), similarly to isinstance and so on…","user":{"login":"ltworf","id":1379609,"avatar_url":"https://avatars1.githubusercontent.com/u/1379609?v=4","gravatar_id":"","url":"https://api.github.com/users/ltworf","html_url":"https://github.com/ltworf","followers_url":"https://api.github.com/users/ltworf/followers","following_url":"https://api.github.com/users/ltworf/following{/other_user}","gists_url":"https://api.github.com/users/ltworf/gists{/gist_id}","starred_url":"https://api.github.com/users/ltworf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ltworf/subscriptions","organizations_url":"https://api.github.com/users/ltworf/orgs","repos_url":"https://api.github.com/users/ltworf/repos","events_url":"https://api.github.com/users/ltworf/events{/privacy}","received_events_url":"https://api.github.com/users/ltworf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-04-19T22:42:00Z","updated_at":"2018-04-20T08:49:08Z","closed_at":null,"author_association":"NONE","body":"Currently, mypy complains about this code:\r\n\r\nIt is checking if value is a `NamedTuple`, and in that case doing something.\r\n\r\n```\r\nif isinstance(value, tuple) and '_fields' in dir(value):\r\n            value._fields\r\n```\r\n\r\n```\r\nerror: \"Tuple[Any, ...]\" has no attribute \"_fields\"\r\n```\r\n\r\nI understand it's a bit dynamic, but the check just happened, so it would be nice if mypy could take into account dir, hasattr.\r\n\r\nAfter all, being instance of something doesn't mean it's not a subclass."},"comment":{"url":"https://api.github.com/repos/python/mypy/issues/comments/383030003","html_url":"https://github.com/python/mypy/issues/4944#issuecomment-383030003","issue_url":"https://api.github.com/repos/python/mypy/issues/4944","id":383030003,"user":{"login":"JukkaL","id":1107911,"avatar_url":"https://avatars2.githubusercontent.com/u/1107911?v=4","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":"2018-04-20T08:49:08Z","updated_at":"2018-04-20T08:49:08Z","author_association":"COLLABORATOR","body":"I only found 7 instances of the `dir()` check in a multi-million line codebase but there were hundreds of `if ... hasattr(...)` instances. Supporting `hasattr()` seems like the way to go. This is still not high priority since the implementation of that check will be a bit tricky as long as mypy doesn't support intersection types."}}
{"actor":{"display_login":"JukkaL"}}