[Python-ideas] Re: Right way to dataclass -> dict conversion.

2020-12-29 Thread Anton Abrosimov
Way 5: Add default `False` `iter` flag to `dataclass` decorator. ``` def __iter__(self) : return ((f.name, getattr(axes, f.name)) for f in fields(axes)) ``` And use: `plot(**dict(axes))` ___ Python-ideas mailing list -- python-ideas@python.org

[Python-ideas] Right way to dataclass -> dict conversion.

2020-12-29 Thread Anton Abrosimov
Example task: ``` from dataclasses import dataclass, asdict, fields from typing import List @dataclass class Point: x: int y: int @dataclass class Axes: title: str points: List[Point] def plot(title: str, points: List[Point]): print(title) for point in points:

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-29 Thread Anton Abrosimov
So, I’m ready to admit that I was mistaken in considering `**` as an operator. Therefore, my further reasoning and suggestions were not correct. If I had the right to vote, I would vote for `dict.update()` like behaviour. Thanks for your attention and clarification. I think it is worth creating

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-28 Thread Anton Abrosimov
Steven D'Aprano wrote: > On Mon, Dec 28, 2020 at 09:06:40AM -0000, Anton Abrosimov wrote: > > Steven D'Aprano wrote: > > You contradict yourself: > > "I can implement any behaviour" > > "I can't realize any other behaviour ..." > > Which is co

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-28 Thread Anton Abrosimov
Chris Angelico wrote: > Allow me to rephrase what I think you're arguing here, and you can > tell me if I'm close to the mark. You close to the mark. :) Chris Angelico wrote: > Given an object of a custom class C, you can make it usable as "x, y, > z = C()" or "f(*C())" or anything else by

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-28 Thread Anton Abrosimov
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

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-28 Thread Anton Abrosimov
Steven D'Aprano wrote: > Why do you want something that isn't a mapping to be usable with mapping > unpacking? I think mapping is not `abc.Mapping` class only. What about: `Iterator[Tuple[str, int]]` ``` @dataclass class MyMap: x: int y: int ``` Is this "mapping"? In Python I can use

[Python-ideas] Re: Add aggregations and joins code-generating library along with itertools

2020-12-27 Thread Anton Abrosimov
1. I think this is too complex for the stdlib. One tool should do one thing. What about the PEP for this project? 2. This is very particular. For those who often convert data in different ways, but do not use pandas, attrs, SQL... 3. What about `typing`? 4. OTF code generation (if I understood

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-27 Thread Anton Abrosimov
Christopher Barker wrote: > My first thought is that for dataclasses, you can use the asdict() method, > and you're done. I thought in a similar way. I'll ask another (7K wtf in 2 years, 3 month) question about converting a dataclass to dict. ___

[Python-ideas] Re: Unpack operator "**" and Mapping

2020-12-27 Thread Anton Abrosimov
0. I believe that the `dict` behavior needs to be frozen. The change will break a lot of existing code, it's too much damage. 0.1. Yes, `keys` is not a good name for internal use, but that's okay. 0.2. If I want to make a class look like a `dict`, I understand that I will get `keys`, `items`...

[Python-ideas] Unpack operator "**" and Mapping

2020-12-26 Thread Anton Abrosimov
I am trying to release comfortable dataclass unpacking using `**` operator. Now I have 5 different ways to do it. But not a single good one. Confused by the implementation of the unpacking operator. So when I try to unpack any custom class, I get the error: `type object argument after ** must