Navigating cpython source using python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Navigating cpython source using python (/thread-34535.html) |
Navigating cpython source using python - quazirfan - Aug-07-2021 I am trying to read python source for some built in function/classes, but sometimes PyCharm is taking me to an autogenerated stub file which makes me think that the source might be written in C. For example, when I try to get to the source of int(), PyCharm take me to this file, Image link: https://imgur.com/a/EYvFmyu The file location in the PyCharm title bar tells me that it is an autogenerated file. I know that cpython source is available at https://github.com/python/cpython, but it's hard to know where to find the source of a particular python function/class. So my question is, where is the C source for int() class? And is there any well known guide out there for someone who is trying to connect python function/classes with corresponding cpython source? RE: Navigating cpython source using python - Gribouillis - Aug-07-2021 The code for the integers is in longobject.c. I don't know a guide to C python source tree, but there are only a limited number of built-in types, it is not very difficult to find the corresponding code with a little experience. RE: Navigating cpython source using python - snippsat - Aug-07-2021 (Aug-07-2021, 05:46 PM)quazirfan Wrote: And is there any well known guide out there for someone who is trying to connect python function/classes with corresponding cpython source?Python source code layout Exploring CPython’s Internals Quote:In documentation look at top if there Python code(Not C) it will link to source code eg calendar Source code: Lib/calendar.py So this source file or method/function if has will also PyCharm or VS Code(Press Ctrl) for linking to source code. pdir2 is fine for getting a nice layout how code is structured,example with calendar in image under. RE: Navigating cpython source using python - quazirfan - Aug-09-2021 Thanks! They both looks fantastic. |