Melab
Melab

Reputation: 2822

Find the portion of code that defines a built-in Python function's name

I've been trying to search the source code of CPython for the names of various built-in functions. What I'm interested in is locating the lines that define the names of these functions, what the Python interpreter's "look-up" procedure looks at when it encounters a function. If I change these lines, then I should be able to change the names of the functions, too.

In this case, I tried searching for the abs function in the C source code files on the GitHub page for CPython. This is the link to the search query I was using. There are 30 results, but none of them contains a string like "abs" or anything like that aside from what looks like strings for documentation.

How would I go about finding these particular lines of code?

Upvotes: 1

Views: 108

Answers (1)

Barmar
Barmar

Reputation: 781098

Here's the part of the search results that specifies the association between the name abs and the function that implements it.

Python/clinic/bltinmodule.c.h 
Showing the top six matches. Last indexed on Oct 1, 2015.

11  #define BUILTIN_ABS_METHODDEF    \
12      {"abs", (PyCFunction)builtin_abs, METH_O, builtin_abs__doc__},

If you go to bltinmodule.c.h you'll find similar definitions for all the built-in Python methods.

Upvotes: 2

Related Questions