On Sun, Dec 27, 2020 at 02:05:38PM -0000, Anton Abrosimov wrote:

> 1. `*`, `**` are operators, but behaviorally they are methods or 
> functions. I think this is the main problem.

No they aren't operators. They aren't in the operator precedence table, 
and they don't have dunders associated with them:

https://docs.python.org/3/reference/expressions.html#operator-precedence

Nor can you use them in places you can use arbitrary expressions:

    >>> a, b, c  = *(1, 2, 3)
      File "<stdin>", line 1
    SyntaxError: can't use starred expression here


> 2. `*` nailed to `Iterable`, not so bad.
> 2.1. It uses the `__iter__` method. I can implement any behaviour.
> 2.2. I only see one problem. I can't realize any other behavior for iterating 
> and unpacking inside a custom class.

You contradict yourself:

"I can implement any behaviour"

"I can't realize any other behaviour ..."

Which is correct?


> 2.3. A new special method for unpacking is a better idea. By default, 
> this method should return `self.__iter__`. This will give control and 
> not break existing code.

You already have control. If you want to use iterator unpacking on an 
object, make it an iterator.

What are you trying to do that you want to use iterator unpacking on 
something but not make it an iterator?

Without a concrete example of why you need:

- to use iterator unpacking on something that isn't an iterator;

- and mapping unpacking on something that isn't a mapping;

all I can say is that his is needless over-generalization. As far as I 
can see, everything in this thread is YAGNI.


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

Reply via email to