|
|
|
|
|
by joshuamorton
3217 days ago
|
|
I think a strong argument against that syntax is that namedtuples are, essentially, an abstract class (or maybe a metaclass). An anonymous namedtuple doesn't really make sense. You want the type information. As of python 3.6, this is already possible: class Point2D(typing.NamedTuple):
x: int
y: int
p = Point2D(x=2, y=4)
If you allow anonymous namedtuples you lose one of the big values of a namedtuple, which is that if I want a Point2D, you can be sure I'm getting a Point2D, and not a Point3D. With anonymous namedtuples, there's nothing stopping you from passing a (x=2, y=3, z=4), when you wanted a (x=2, y=3). And maybe that will work fine, but maybe not (or the reverse).All this is to say, an anonymous namedtuple is an oxymoron. NamedTuples should be named. This isn't a "really good idea". |
|