1

I think Eclipse has this with Java std lib. I believe you can search Object then go view the source of the Object class.

I want to be able to search for and view the source of something like list in Python.

In Pycharm, I can go to declaration of anything such as import os or c = ClassFromMyModule(), but with a dict or list, it's not the same.

I can't go to declaration of a literal or an operator. Such as:

d = {}
l = ['hello', 'there']
my_str = "hello there"
a = b + c
James T.
  • 910
  • 1
  • 11
  • 24
  • Related: [Why do some built-in Python functions only have pass?](https://stackoverflow.com/q/38384206/3357935) – Stevoisiak Mar 14 '18 at 20:05

2 Answers2

1
import builtins

Go to declaration of this.

James T.
  • 910
  • 1
  • 11
  • 24
1

You can simply write something like:

x = list()

and then hit Ctrl and click on list. It will bring you to a file called builtins.py, but lists and dictionaries are builtins, these are usually implemented by the interpreter. So as a result these have no Python implementation, it will show you something like:

class list(object):
    """
    list() -> new empty list
    list(iterable) -> new list initialized from iterable's items
    """
    def append(self, p_object): # real signature unknown; restored from __doc__
        """ L.append(object) -> None -- append object to end """
        pass

    def clear(self): # real signature unknown; restored from __doc__
        """ L.clear() -> None -- remove all items from L """
        pass
    # ...

So it is actually more a "virtual" class definition that is generated based on the documentation. The list object is not implemented in Python itself: it is an object implemented in the Python interpreter. This makes sense since it is impossible to implement a list (with fast random access) without having something like a list/array.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555