I believe you made a mess.

For all attribute getting needs, I think operator.attrgetter should
suffice. No need to implement it yourself.

For attribute setting needs, maybe we can add an equivalent
operator.attrsetter. I can see myself using it from time to time.

Easy solution, solves the problem, makes sense, we can even implement an
itemsetter much like itemgetter for completeness, as the implementation
will probably be easy and well understood.

What do you say?

-- Bar Harel

On Tue, Oct 22, 2019, 3:25 AM Kyle Lahnakoski <klahnako...@mozilla.com>
wrote:

>
> On 2019-10-21 10:44, gedizgu...@gmail.com wrote:
> > m and n are lists or dicts or enumerates or classes or anything it can
> be assigned like following:
> >
> > instead of :
> >
> > m.a=n.a;
> > m.b=n.b;
> > m.c=n.c;
> > ...
> >
> > I suggest:
> >
> > a,b,c of m to n ;
>
> Interesting.  I also saw this type of redundancy in my code. Instead of
> making a function, like `copy_attrs()` I changed my APIs to accept
> over-specified attributes.  Instead, I would write
>
> m = n
>
> ... or simply use `n` where `m` was expected.  Yes, `n` would have more
> attributes than needed, but that is solved by ensuring the receiver can
> gracefully reject the extra attributes; I decorate pedantic functions
> that complain about extra parameters.
>
> In your other example, I would write:
>
> adiv=document.createElement("div")
> adiv.style = comp
>
> There is the problem of unfortunate namespace overlap; where the
> destination expects some attribute X and the source has an attribute of
> the same name, X,  but the value is wrong.  But this is not a large
> problem: You can plan your attribute names on a program-wide scale so
> that the same attribute name means the same thing across your whole
> program, and different attribute names mean different things across your
> whole program.  This does not require too much forward planning, rather
> more refactoring as you rename parameters to match, or differ, as
> needed.  This is what the ES6 structuring/destructuring is  promoting.
> Consider a function that uses `adiv`:
>
> drawBox = (adiv) => {
>      const {x, y, height, width} = adiv.style;
> }
>
> the extra attributes of `comp` are ignored; specific attribute copying
> is not required.
>
>
> _______________________________________________
> 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/FY24FAGNQAGTA5CRZCI2WWEGF5RQPPPD/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
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/CG2F7P3VAJOFQMU3SD6FSQYXOSYTZI5B/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to