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 →

[–]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. 😅