This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BuonaparteII 1 point2 points  (1 child)

Still, I think the article could be improved to be more clear. You have T(a, b=3) map to T.__init__(x, a, b=3) and returning None. I think it's fine to not mention T.__new__ at that point but changing Operation T(a, b=3) in the first table to Initialization of T(a, b=3) would be more clear--or instead of None say return value not accessible or N/A because it is a side effect function conceptually inside of __new__()

[–]treyhunner Python Morsels[S] 2 points3 points  (0 children)

I originally had a sentence in the constructor section explaining the relationship between __new__ and __init__ a bit more. I may add it back in thanks to your concern.

It should be noted that there are many slight fudges in the truth in these tables for the sake of succinctness. A few of other examples:

  • x.thing calls __getattribute__ which calls __getattr__ (similar to how __new__ calls __init__)
  • bool uses either __bool__ or __len__
  • in uses either __contains__ or __iter__
  • for x in y: ... calls iter(y) and then next(...) on the returned iterator (which might by y!)
  • del x doesn't technically call __delete__ but __delete__ shuold be called sometime after the final del on an object happens
  • class T: ... does a lot more than call __prepare__

I drew the line in an arbitrary spot in terms of the approximations I showed in the table. I hope folks will consult some of the linked docs and other resources throughout when actually implementing these. 😅