[Proposal] Have a Java inheritance chain for standard types implemented
Currently (almost) all types inherit from org.python.types.Object. While this reflects the inheritance chain on the Python side (most types inherit from object), this makes the implementation unnecessarily difficult, and require a lot of duplicate code because we can’t really utilise Java polymorphism idioms, such as Generics and Interfaces. This is most problematic in collection types, but also poses a problem with other types.
One example is the List::extend implementation merged in #645—the whole if-else block is unnecessary if Generics can me used.
As @freakboy3742 mentioned in #486, the Java inheritance chain does not affect the Python inheritance chain. Since inheritance and interfacing is front and centre in Java’s OOP, we should use it.
Python provides a set of abstract base classes that can offers a good sense how the inheritance chain should look like. Some extra classes might be necessary (I think) to abstract the internal structures, but not much. This could probably be a beginning for solution toward #582.
This is a very interesting idea. Interfaces certain seem like they could be very useful, as long as we can contain and prevent them from exploding in number with some careful design...
This definitely looks like something worth exploring - although I suspect the devil will be in the details.
Have you got any concrete ideas for how to implement this? It is a case of picking features one at a time and interfacing/inheriting them until everything is cleaned up?
Not really, what I currently have in mind is to loosely follow the collection ABCs, implementing what we think is good along the way. Classes that can provide the most benefits right now IMO are Iterable (#645 and a lot of other similar code would benefit) and ByteString (Bytes and Bytearray rightly share most of their implementation). Another one I can think of is the number classes (#582).