Package to show object properties in python


#1

I’m new to Atom & mostly new to Python so apologies if this is a dumb question.

When learning a new SDK/library, it helps to be able to quickly see what an object is and what properties/methods it has. In Python this is pretty easy to do with dir(object) or help(object), etc. but when I’m writing code, it’s annoying to have to add this line and run my code just to understand what this object is about and what it has. It would be nice if there was some package/plugin for atom that would help here.

I got the autocomplete package for Python (https://atom.io/packages/autocomplete-python) but it doesn’t seem to do help…

For example (using the OneDrive API SDK), I have this code:

root_folder = client.item(drive=“me”, id=“root”).children.get()
root_folder.

auto complete suggests just “self” but dir(root_folder) shows:

class’, ‘delattr’, ‘dict’, ‘dir’, ‘doc’, ‘eq’, ‘format’, ‘ge’, ‘getattribute’, ‘getitem’, ‘gt’, ‘hash’, ‘init’, ‘le’, ‘len’, ‘lt’, ‘module’, ‘ne’, ‘new’, ‘reduce’, ‘reduce_ex’, ‘repr’, ‘setattr’, ‘sizeof’, ‘str’, ‘subclasshook’, ‘weakref’, ‘_init_next_page_request’, ‘_prop_list’, ‘children’, 'next_page_request’]


#2

The problem with dynamic languages (like Python) is that you have to know what type root_folder is in order to give that list that you’re asking for. The problem is that since any function can return any type, there’s no guarantee that the code client.item(drive="me", id="root").children.get() will return the type you’re expecting. The only way to know for certain is to execute the code.

Now, one can make educated guesses. If, for example, I knew:

  1. That you were using the OneDrive SDK
  2. That client was a certain type
  3. That item().children returned a certain type when called on the type in step #2 under normal circumstances
  4. That get() returned a certain type when called on the type in step #3 under normal circumstances

Then Atom could make the supposition that root_folder would have the properties you list. But that’s a lot of knowledge about the language, the interpreter, and the libraries that you’re using … and a lot of cross-referencing and analysis that would have to happen.

Some of the autocomplete packages for some languages are partially to that point … but mostly for the standard language components and standard libraries, not for random third-party libraries yet.

(Sorry if that was a bit of a brain dump when you were looking for a simple answer. Let me know if I didn’t answer your question and I’ll try to do better :grinning: )


#3

Thanks for that – it totally answered the question was what I suspected.