Steven D'Aprano wrote:
> On Sun, Dec 27, 2020 at 02:05:38PM -0000, Anton Abrosimov wrote:
> >
> > *, ** 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
Hmm... PEP 448 -- Additional Unpacking Generalizations:
> This PEP proposes extended usages of the * iterable unpacking operator and **
> dictionary unpacking operators to allow unpacking in more positions, an
> arbitrary number of times, and in additional circumstances. Specifically, in
> function calls, in comprehensions and generator expressions, and in displays.
Steven D'Aprano wrote:
> You contradict yourself:
> "I can implement any behaviour"
> "I can't realize any other behaviour ..."
> Which is correct?
I apologize for my english, I meant that I cannot implement the following
behavior inside the class:
```
class MyClass:
def __iter__(self):
return self.items_for_iteration
def __unpack__(self):
return self.items_for_unpack
```
I have to make a separate method and have to rely on the user of the class.
Steven D'Aprano wrote:
> What are you trying to do that you want to use iterator unpacking on
> something but not make it an iterator?
How can I implement an unpackable dataclass without littering it with
non-dunder methods?
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/6FGSOQE4AQPJLVOWFXR23GVC2HJB7VBY/
Code of Conduct: http://python.org/psf/codeofconduct/