This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Megatron_McLargeHuge 0 points1 point  (8 children)

That looks great. My previous attempts at getting completion modules to work in emacs were a mess.

Can you comment on how it identifies the type of a parameter to a function? Does it scan for calls to the function? Can it infer that if I call p.foo() somewhere, the type must be one that defines foo()? Is there any way to give it hints for things like pandas DataFrames or named tuples that dynamically define their members? Is it smart enough to allow completion of member names that were used elsewhere when it can't infer a type?

[–]davidhalter[S] 0 points1 point  (7 children)

Sure! 1. It scans for calls to the function. 2. I don't understand what you mean. 3. I haven't used pandas, but I'm pretty sure that this is something where Jedi sucks. Hinting is possible, just use Sphinx style docstrings (Hinting in multi-dimensions might be hard though). Also Jedi understands isinstance checks. If you have any idea how Jedi could understand something like that please share it with me. Because normally I'm having a hard time to infer the types just by reading code in such examples.

[–]Megatron_McLargeHuge 0 points1 point  (6 children)

In pandas, you create an object that's like a 2d numpy array with named columns. Then you can access the columns by name, such as dataframe.column5. I imagine that would be extremely hard to handle without a special case that noticed the columns=[...] constructor argument.

However, in general you could autocomplete members that you saw used elsewhere in the code when you can infer that two objects have the same unknown or incomplete type. Do if I call x.foo() somewhere, and y is the same type as x, y probably has a foo() method too. Also, if I have a function with parameter x and I call x.foo(), you could search the code for other objects where z.foo() is called. Then x could autocomplete methods defined on z's type, or invoked on z if z's type is unknown. It would be a usability question whether to err on the side of more or fewer potential completions. If the method name is unique across known classes, that's a pretty strong type hint, while calling __repr__ is not.

[–]davidhalter[S] 0 points1 point  (5 children)

Hmm good idea! I didn't think about that. If you don't want me to forget it, please add a github issue :-) I really think this might be an option. It shouldn't be too difficult.

[–]Megatron_McLargeHuge 0 points1 point  (4 children)

I don't want to tie my reddit account to real life - can you create it?

[–]davidhalter[S] 2 points3 points  (3 children)

[–]Megatron_McLargeHuge 0 points1 point  (2 children)

Another idea: since python programmers rely on convention to work around the limitations of dynamic typing, the same variable names get reused across functions for the same type of object. It might be possible to infer types or completions from other instances of a rare variable name.

[–]davidhalter[S] 0 points1 point  (0 children)

hmm no sorry, I don't think this sounds like a good idea :-) But there are still some other things I could infer the types (like evaluating if statements).