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
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:
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
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
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
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
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
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
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.
___
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`...
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
11 matches
Mail list logo