[Python-Dev] Is static typing still optional? (original) (raw)
Eric V. Smith eric at trueblade.com
Sun Dec 10 18:23:30 EST 2017
- Previous message (by thread): [Python-Dev] Is static typing still optional?
- Next message (by thread): [Python-Dev] Is static typing still optional?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 12/10/2017 5:00 PM, Raymond Hettinger wrote:
On Dec 10, 2017, at 1:37 PM, Eric V. Smith <eric at trueblade.com> wrote: On 12/10/2017 4:29 PM, Ivan Levkivskyi wrote: On 10 December 2017 at 22:24, Raymond Hettinger <raymond.hettinger at gmail.com<mailto:raymond.hettinger at gmail.com>> wrote: Without typing (only the first currently works): Point = namedtuple('Point', ['x', 'y', 'z']) # underlying store is a tuple Point = makedataclass('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 makedataclass() pass through keyword arguments to processclass(), so that this will work: Point = makedataclass('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.
- Previous message (by thread): [Python-Dev] Is static typing still optional?
- Next message (by thread): [Python-Dev] Is static typing still optional?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]