4 Comments
Apr 13Liked by Abhinav Upadhyay

The **ob_item gave away the double pointer play (pointer to the reference) and then as they say, the rest is history 😊. Great writing by the way!

Expand full comment

For me this is not so much shocking.

Simply lists are stored by reference and if you copy that reference you are still pointing to the same memory area/object.

Maybe because I have a C++ background this doesn’t seem so surprising.

A similar thing happens when you want to have a default empty collection (like a list) in a function argument: if you pass ‘def fun(my_list=[])’, that list is a single one and not created every time you invoke the function (as intended most of the times).

The solution to this problem is to use ‘list()’ instead of ‘[]’

Expand full comment
Apr 11·edited Apr 11

I have two in detail articles about Object and Types in CPython and How list.append works in CPython in here: https://medium.com/@mahdihaghverdi

Expand full comment

>"Even though the function name is PyNumber_Multiply, it handles the * operator for both numeric types and sequence types." is an example where providing additional functionality screws things making explanations and justifications necessary and from the point of view described with the idea of an oOo way a nice evidence that https://dev.to/ooosys/the-ooo-way-part-3-why-using-programming-languages-for-programming-is-a-bad-idea-27p8 using programming languages for programming is a bad idea.

Expand full comment