On Wed, Apr 2, 2014, at 17:27, Steven D'Aprano wrote:
But Eric's suggestion skips creating a distinct class and gives you an instance straight away. So what class will the instance belong to? There are three obvious possibilities, and they're all unfortunate:
(1) every instance is a singleton of a unique class;
(2) there is a single NamedTuple class that every instance belongs to;
(3) the namedtuple literal has to cache the keys it has seen, and return the same class when given the same keys in the same order.
(4) Step 3 is done in the compiler, and therefore only namedtuple literals in the same module (or same freshly eval/exec'd string) will have the same type. I think this is what C# does, though you're not supposed to compare them by type, work with their types much, or really store the objects in a non-ephemeral way anyway. Really, it'd almost be nicer to have a _single_ "bag of attributes" type [i.e. class c: pass], and literals for it.