3

If I go to the implementation of let's say the next() builtin function, I'm forwarded to the builtins.py module to following code:

def next(iterator, default=None): # real signature unknown; restored from __doc__
    """
    next(iterator[, default])
    
    Return the next item from the iterator. If default is given and the iterator
    is exhausted, it is returned instead of raising StopIteration.
    """
    pass

Now, it looks like this functions does nothing but obviously that's not the case.

I understand that this function is implemented in C under the hood, but how and when is this function(or other builtin functions) mapped to the underlying C implementation?

If you have an answer to this question, can you please also provide links that I can read in order to better unterstand this topic?

I'm not asking, where the code is, but how and when the function is mapped to that code

Thank you.

Filippo Boido
  • 1,136
  • 7
  • 11
  • 2
    What you're looking at isn't actually part of Python. It's not like this stub is ever "mapped to" the "actual implementation" in C. There is only the actual implementation in C. This stub file is just used by your IDE to, well, stub the function signature for auto-completion etc. – deceze Feb 26 '21 at 10:34
  • Would still be interesting to know how next() is interpreted and linked to the C implementation.. – Filippo Boido Feb 26 '21 at 10:40
  • You're basically asking how Python works…? How it finds any name, whether builtin or user defined? Seems a bit broad. What about the process do or don't you understand? Perhaps we can fill in some gaps for you, if you tell us more about what gaps you have. – deceze Feb 26 '21 at 10:43
  • Do you know how next() is interpreted and linked to the C implementation or not? – Filippo Boido Feb 26 '21 at 10:44

0 Answers0