On 12/10/2017 5:00 PM, Raymond Hettinger wrote:


On Dec 10, 2017, at 1:37 PM, Eric V. Smith <e...@trueblade.com> wrote:

On 12/10/2017 4:29 PM, Ivan Levkivskyi wrote:
On 10 December 2017 at 22:24, Raymond Hettinger 
<raymond.hettin...@gmail.com<mailto:raymond.hettin...@gmail.com>> wrote:
    Without typing (only the first currently works):
         Point = namedtuple('Point', ['x', 'y', 'z'])          #
    underlying store is a tuple
         Point = make_dataclass('Point', ['x', 'y', 'z'])      #
    underlying store is an instance dict
Hm, I think this is a bug in implementation. The second form should also work.

Agreed.

I have a bunch of pending changes for dataclasses. I'll add this.

Eric.

Thanks Eric and Ivan.  You're both very responsive.  I appreciate the enormous 
efforts you're putting in to getting this right.

Thank you for your feedback. It's very helpful.

I see a couple of options:
1a: Use a default type annotation, if one is not is supplied. typing.Any would presumably make the most sense.
1b: Use None if not type is supplied.
2: Rework the code to not require annotations at all.

I think I'd prefer 1a, since it's easy. However, typing is not currently imported by dataclasses.py. There's an argument that it really needs to be, and I should just bite the bullet and live with it. Possibly with Ivan's PEP 560 work my concern on importing typing goes away.

1b would be easy, but I don't like using non-types for annotations. 2 would be okay, but then that would be the only time __annotations__ wouldn't be set on a dataclass.

I suggest two other fix-ups:

1) Let make_dataclass() pass through keyword arguments to _process_class(), so 
that this will work:

     Point = make_dataclass('Point', ['x', 'y', 'z'], order=True)

Agreed.

2) Change the default value for "hash" from "None" to "False".  This might take 
a little effort because there is currently an oddity where setting hash=False causes it to be hashable.  I'm 
pretty sure this wasn't intended ;-)

It's sufficiently confusing that I need to sit down when I have some free time and noodle this through. But it's still on my radar.

Eric.

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to