On Mon, 30 Sep 2019 at 10:02, Stephen J. Turnbull <turnbull.stephen.fw@u.tsukuba.ac.jp> wrote:
Steven D'Aprano writes:
On Sun, Sep 29, 2019 at 11:27:32AM +0100, Oscar Benjamin wrote:
That's the point that I would make as well. What can you do with an object that is only known to be Subscriptable?
I can subscript it. What did you expect the answer to be?
Technical questions: does "Subscriptable" mean non-negative ints only, or does it include the negative "count from the end" protocol? How about slices?
I think we've established that what Steven wants is nothing more than a "robust" version of hasattr(obj, "__getitem__"). It's (in my view) sad that the simple hasattr test is no longer sufficient, and in particular that if you want robustness, Python has changed to the point where a pseudo subclass check is the "right" way to check for an object that has certain properties. But I guess this is the case, and therefore the omission of a Subscriptable ABC is something that may need to be addressed. Maybe rather than proliferating ABCs like this, exposing the internal function in the ABC that does the "robust" version of the hasattr test would be more flexible? I guess that depends on whether you find the "subclass of an ABC" approach acceptable. To me, it feels too much like "object oriented everywhere" languages like Java, which was always an issue I had with ABCs, but as Steven said, that ship has probably sailed by now[1]. Paul [1] Much like typing, where it's getting harder and harder if you work on larger projects to view it as "optional" when the project standards mandate it...