![](https://secure.gravatar.com/avatar/176220408ba450411279916772c36066.jpg?s=120&d=mm&r=g)
On Sat, Jan 15, 2022 at 2:06 AM Paul Moore <p.f.moore@gmail.com> wrote:
Personally, I dislike the presumption that you state in the bpo, that typing and linters have changed things so that being a sequence is more closely tied to implementing the Sequence abc these days. I consider it a flaw in typing and linters if that’s the case, not something to embrace.
Exactly. *maybe* the ecosystem has shifted, but Python is and I hope will always remain fundamentally a dynamically, duck typed language. We sure don't want to build any other assumptions into the C API itself. From the bpo: "Wherever you'd try to pass sre_parse.SubPattern, the linter will throw an error saying it's not a Sequence even if it fully behaves like one" Then that linter is broken, plain and simple. If a static type checker fails on that, then that's a limitation of static type checking. In fact, ideally it would pass even if it didn't fully support the Sequence ABC. For example, if I have a function that needs only to use one or two methods of a Sequence, I should not type the input as Sequence, and also expect it to work in a duck typed context. You can (and if you're being thorough, should) define a type that only requires the methods that you need. I think MyPy's Protocol can be used for that, for example. -CHB -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython