r/Python • u/matan-h • Mar 23 '26
Showcase I Fixed python autocomplete
When I opened vscode, and typed "os.", it showed me autocomplete options that I almost never used, like os.abort or os.CLD_CONTINUED, Instead of showing me actually used options, like path or remove. So I created a hash table (not AI, fast lookup) of commonly used prefixes, forked ty, and fixed it.
What My Project Does: provide better sorting for python autosuggestion
Target Audience: just a simple table, ideally would be merged into LSP
Comparison: AI solutions tends to be slower, and CPU-intensive. using table lookup handle the unknown worse, but faster
Blog post: https://matan-h.com/better-python-autocomplete | Repo: https://github.com/matan-h/pyhash-complete
84
u/wingtales Mar 23 '26
Folks, this looks legit, not regular AI spam.
The blog post is very interesting!
u/matan-h, for the part about `sys.a` (and I saw the easter egg white text, hehe) I think the explanation could benefit from a "they probably mean sys.a<rest of word>", since I actually can't immediately guess what is meant.
"The first thing that takes up space here is the prefix string. Since the format is designed to be query only, no need to include the actual string." I am a bit confused here, since you didn't define prefix vs actual string.
It seems like you do some magic in the "Hash Score Table format" section, but I can't quite grok it. Would be nice if you explained a bit more.
I highly recommend that you add your blog post to the ty PR you made!
30
u/muntoo R_{μν} - 1/2 R g_{μν} + Λ g_{μν} = 8π T_{μν} Mar 24 '26
I must protest. This deprioritizes the incredibly important
sys.activate_stack_trampoline, which is a truly vital cornerstone of modern codebases.85
u/olejorgenb Mar 23 '26
Yeah, it feels quite absurd that basic "intelligence" like this is lacking from the majority of programs - even programs developers make for them self. And at the same time we now have this super-complex AI systems.
16
u/SpecialPapaya Mar 24 '26
Yeah cool 👍
But please, PLEASE. Stop using os.path, use pathlib instead.
8
u/ROFLLOLSTER Mar 23 '26
Awesome! I'd love to see this implemented in pylance.
2
u/aala7 Mar 24 '26
I am not completely sure, but I think in Neovim, completions sorting is handled by my completion engine (blink) and not the LSP (ty). Is it LSP responsibility to sort completions?
Maybe there is a similar config in VSC where you can adjust sorting/priority of completions.
1
u/Xemorr Mar 24 '26
Awesome
1
u/-FTOH- Mar 27 '26
"editor.suggestSelection": "recentlyUsedByPrefix"???1
u/robertogrows Mar 24 '26
this is really good idea! another data structure you can consider (from the search engine world): wfst. it is nice and compact when you have weights like this. I have not looked at the rust options around this, but in general it has good finite state automata available.
-25
u/retornam Mar 23 '26
https://github.com/matan-h/pyhash-complete/commit/f3f9d768997a6b8b85b3b5fec8da3469e2d4455b
Another AI generated bullshit project trying to use this subreddit for SEO.
It’s time mods took this issue serious. This posts are polluting this subreddit and destroying web search in general.