Is there a "mind map", UML diagram, graphic, or some solid reference for the different python types and the magic methods they must implement?
I'm using Python 3.8. The data model docs and built-in types docs docs are very terse and it would help me to see a high-level overview of the different protocols that exist for different types in python (I've "learned" (read?) that, e.g., to implement an "immutable-like" object, you must adhere to the Immutable Protocol
in python, which means you must implement __len__
and __getitem__
. To make it "mutable-like", you must further add __setitem__
and __delitem__
).
I don't see (from as far as I've searched) the word "protocol" being used in the python docs, and the closest good description seems to come from the collections abstract base classes module. However, as a newcomer, I'm not sure if collections.abc
is something else entirely, or if the information provided there applies to the python builtin types (i.e. list
, tuple
, dict
, etc.; particularly becuase the collections.abc
docs states it "provid[es] alternatives to Python’s general purpose built-in containers, dict, list, set, and tuple" and second because I wouldn't think to go to the collections
module if I wanted to learn about the default builtins from the python language itself).
Does anyone have a solid resource? It would be helpful if the information were in a kind of inheritance relationship format so that info doesn't get repeated. For instance, in my example above, rather than say that a mutable-like
object implements __len__
, __getitem__
, __setitem__
, and __delitem__
, it would be easier for my puny brain to hold if it were "chunked" and the info was something like "a mutable-like
object inherits from immutable-like
and adds __setitem__
, and __delitem__
.
Are there any thoughts? I think this is a huge source of confusion for newcomers and many errors result from a misunderstanding of the data types in python.