On Sat, Jan 15, 2022 at 2:06 AM Paul Moore <p.f.mo...@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
_______________________________________________
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/5PDJ5SUJADTPUNLOBSOUU4DZDJIOFPTK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to