On Fri, 23 Apr 2021, 12:34 pm Inada Naoki, <songofacandy@gmail.com> wrote:

I think using ABC to distinguish sequence or mapping is a bad idea.

There are three policies:

a) Use duck-typing; just us it as sequence. No type check at all.
b) Use strict type checking; isinstance(x, list) / isinstance(x, (list, tuple)).
c) Use ABC.

But (c) is broken by design. It is not fixable.
IMHO, We should chose (a) or (b) and reject any idea relying on Sequence ABC.


That ship sailed long ago, since distinguishing sequences from mappings was one of the original motivating use cases for ABCs (see the last sentence inĀ https://www.python.org/dev/peps/pep-3119/#abcs-vs-duck-typing ).

One of the important things to remember about ABCs is that passing a *runtime* isinstance check is a matter of calling "the_abc.register(my_type)". Hence the comment earlier in the thread that with ABCs, passing "isinstance(obj, the_abc)" becomes just another criterion for quacking like a duck.

Cheers,
Nick.