metadict icon indicating copy to clipboard operation
metadict copied to clipboard

PyCharm static auto-completion not work

Open evan0greenup opened this issue 2 years ago • 2 comments

It will work when in PyCharm's Python Console, but in python source code, when define the MetaDict with existed dict as input parameter or use __setitem__ annotation assignment. This item will not listed in auto-complete list for the code afterward.

The MetaDict is not in memory. Maybe statically auto-complete need to be implement in another approach. collections.namedtuple received its field from parameter as an Iterable of string. But it can make PyCharm auto-complete works statically. May be ideas from collections.namedtuple can inspire the design of MetaDict.

What is your opinion? @LarsHill

evan0greenup avatar Aug 04 '22 12:08 evan0greenup

Thanks for the input. I checked the source code of collections.namedtuple and they essentially create an entire class object with its namespace on the fly, which is probably why PyCharm can introspect the class from within the code editor and offer auto-complete functionality.

It is an interesting approach and if I find the time I will look deeper into it. However, I cannot promise I'll get to it anytime soon since it likely takes more time and involves a complete refactor/rewrite of MetaDict.

If you or someone else wants to give it a shot, I am always open for pull requests in the meantime.

LarsHill avatar Aug 08 '22 17:08 LarsHill

hey! i did an experiment about collections.namedtuple. i copied the namedtuple function to my python lib file (such as my_tuple.py) , and try to use it in my other source code, but PyCharm auto-complete didnt work like the collections.namedtuple, so did the vscode. @evan0greenup

So this auto-completion seems to be done for the function collections.namedtuple of the python standard library. Pycharm only analyzes the parameters of the external call and starts to complete the work.

Due to time constraints, I haven't tested it in depth. more testing may be needed.

I think the feasible solution is to make a Pycharm plug-in, but it may be more complicated. @LarsHill

LincolnYe avatar Aug 27 '23 20:08 LincolnYe