On Fri, Aug 14, 2020, 7:45 PM David Mertz email@example.com wrote:
On Fri, Aug 14, 2020, 7:39 PM Caleb Donovick
class T(Protocol): x: int y: str # with some abuse of notation obviously these would generate unique typesassert T == Struct[x=int, y=str]
I don't see what that can possible get you that `Struct(x=int, y=str)`
I'm +0 on the idea, but I don't think "square brackets look nicer" is sufficient reason for a change.
One problem is type hint creation has been extended to built-ins in python 3.9, so that you do not have to import Dict, List, et al anymore.
Without kwd args inside [ ], you would not be able to do this:
Vector = dict[i=float, j=float]
...but for obvious reasons, call syntax using built ins to create custom type hints isn't an option :
dict(i=float, j=float) # this syntax isn't available
So the improvement allowing usage of built ins for typing is somewhat negated.
Instead you would have to import Dict from typing:
Vector = typing.Dict(i=str, j=float)
To me it is instructive that the line of code above currently causes a TypeError. For some reason, the mpy team decided not to go this direction, and instead in Python 3.8 introduced typing.TypedDict:
class Vector(TypedDict): i = float j = float
I suppose type hint creation could be extended to allow syntax you are proposing, like Dict(i=float, j=float). But it certainly appears to me that it was rejected for a reason, though I can't say what that reason is (I'm sure someone else could).