{"comment":{"url":"https://api.github.com/repos/d42/jedi/comments/14664720","html_url":"https://github.com/d42/jedi/commit/b11229407aabf404b1432521600c27def16d058a#commitcomment-14664720","id":14664720,"user":{"login":"davidhalter","id":748594,"avatar_url":"https://avatars.githubusercontent.com/u/748594?v=3","gravatar_id":"","url":"https://api.github.com/users/davidhalter","html_url":"https://github.com/davidhalter","followers_url":"https://api.github.com/users/davidhalter/followers","following_url":"https://api.github.com/users/davidhalter/following{/other_user}","gists_url":"https://api.github.com/users/davidhalter/gists{/gist_id}","starred_url":"https://api.github.com/users/davidhalter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidhalter/subscriptions","organizations_url":"https://api.github.com/users/davidhalter/orgs","repos_url":"https://api.github.com/users/davidhalter/repos","events_url":"https://api.github.com/users/davidhalter/events{/privacy}","received_events_url":"https://api.github.com/users/davidhalter/received_events","type":"User","site_admin":false},"position":null,"line":null,"path":"","commit_id":"b11229407aabf404b1432521600c27def16d058a","created_at":"2015-11-28T16:21:52Z","updated_at":"2015-11-28T16:21:52Z","body":"@d42 Well, it's a pretty much ok solution for completion.\r\n\r\nHowever it shouldn't interfere with `goto_definition` and other stuff. This would have implications on type inference. You want `__slots__` to just affect completion. This means that you check if you're using completion on an instance (`if isinstance(x, Instance)`) and then you try to lookup `__slots__`. However, I would do it with the normal type lookup of Jedi. You can do it with the parser, but it's easier (and more precise) with something like this:\r\n\r\n```\r\nif isinstance(context, Instance):\r\n    for cls in instance.py__mro__():\r\n        for typ in iterable.py__iter__(evaluator, evaluator.find_types(cls, '__slots__')):\r\n            if isinstance(typ, CompiledObject) and isinstance(typ.obj, str):\r\n                # If it's a CompiledObject and a string, we can continue adding those\r\n                add_to_completions(typ.obj)  # or list.append(typ.obj)\r\n```\r\n\r\nGenerally I have started to try using similar names to Python's magic methods, prefixed with a `py`, because this is something people know and understand. \r\nNote however, that `py__iter__` only exists in the latest commits in the linter branch, so you need to use that branch. Your idea of using the syntax tree was pretty good and also works, but in the end I think using Jedi's own type inference is the better choice. The type inference is mostly superior, because that's the way how Python itself does it.\r\n\r\nIt's very important that you implement all of this within `api.Script.completions`, because there you don't interfere with the type inference logic.\r\n\r\nI hope I haven't given you the whole solution already, haha :-)"}}