On Fri, 23 Apr 2021, 12:34 pm Inada Naoki, <songofaca...@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. >
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/6G5EBNTHXMQJAD6FRVRPNDHNZBPVAOIK/ Code of Conduct: http://python.org/psf/codeofconduct/