On Thu, Oct 21, 2021 at 01:46:27PM +1100, Steven D'Aprano wrote:
> On Tue, Oct 19, 2021 at 05:09:42PM -0700, Michael Selik wrote:

> > If the motivation for this operator is chained lookups, how about adding a
> > feature to the operator module, first? It seems natural to add a
> > keyword-only argument to `attrgetter`, and it's a lighter touch than
> > implementing a new operator. If use becomes widespread, that gives more
> > weight to PEP 505.
> 
> I agree that this is a nice way forward, and a useful function in its 
> own right.

On further thought, I no longer agree. Or at least, I think we need to 
think a lot harder about the API before adding any sort of chained 
attribute getter into the stdlib. If we get it wrong, we'll be stuck 
with it until Python 5000.

The problem is that any sort of code equivalent to:

    try:
        return obj.chain.of.attribute.lookups
    except AttributeError:
        return None

risks silently hiding genuine coding errors. This seems to be an 
anti-pattern, or at least a foot-gun. And it is certainly not equivalent 
to, or a replacement for, PEP 505.

Same applies to variants similar to attrgetter.



-- 
Steve
_______________________________________________
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/IRO7Z2IEV3I7X5EZZRNWCLDMJRCWALGS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to