On 2020-12-29 10:30, Guido van Rossum wrote:
I don't understand why LBYL is considered such an anti-pattern. It helps
produce much clearer error messages in this case for users who are
exploring this feature, and distinguishing *early* between sequences and
mappings is important for that. Long ago we decided that the distinctive
feature is that mappings have a `keys()` method whereas sequences don't
(and users who add a `keys()` method to a sequence are just asking for
trouble). So that's what we use.
I think what is confusing to me that is that it was not ever clear to
me that such a decision was ever made. I can't find anything on
python.org/docs that explicitly says that that is how a mapping defines
its mapping behavior, let alone that that specifically defines unpacking
behavior.
It seems the real issue here is one of documentation. My view tends to
me that python.org/docs is the ultimate authority on the language's
behavior. Unfortunately it sometimes doesn't work that way, and I've
been meaning to make a post on this list about it, which hopefully I
will do at some point. But like, important stuff like "** unpacking is
implemented with this method" should not be buried in a PEP, nor a
docstring, and certainly not a source-code comment. As far as I can
see, on python.org/docs all we have is that the Mapping abc lists keys()
as a mixin method, but nowhere actually says that those methods are also
what is used to implement syntactic things like **-unpacking. I see
this is a major oversight and I think the docs should be updated more
comprehensively when PEPs are approved or decisions like the one you
describe are made, so that the actual, real documentation --- not the
PEPs! --- is always reflective and in fact definitional of the
language's behavior. In other words, what the language is accountable
to is the documentation on python.org/docs and nothing else.
--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no
path, and leave a trail."
--author unknown
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/KYYJ6V2DWPWCVTICSF6SCLIUHMZEVB5E/
Code of Conduct: http://python.org/psf/codeofconduct/