On Wed, Oct 16, 2019 at 05:27:31PM -0000, Steve Jorgensen wrote:
I feel like this proposal is not quite right, but maybe the idea will provoke some thoughts about something similar that -would- be right.
The idea first came to me upon realizing that since `namedtuple` classes have no special base class beyond `tuple`, there should be some way of identifying them as being primarily structural, even though they are instances of `tuple` which, in other cases, usually means something that is primarily sequential.
I don't think that "structural" is the word you are looking for. Lists and tuples and sets are all structural. That's why they're called "data structures".
Perhaps "collection of named fields"? Sorry, I can't think of a shorter name.
I'm going to put aside the question of whether named tuples are "primarily" tuples or named attributes.
You are begging the question: why "should" there be some means of identifying named tuples specifically? I'm not saying that there shouldn't be, but you haven't given any reasons why this is useful. What calling code will want to treat these named tuples the same way and so need to distinguish them as "Structs"?
namedtuple("Point", ("x", "y"))
namedtuple("Employee", ("name", "position", "id"))
There are also built-in named-tuples that don't include the _asdict method, such as sys.hash_info. Other "Structs" (collections of named fields) might include SimpleNamespace and Dataclasses, not to mention any object with named attributes holding data.
So it isn't really clear to me that this is a useful, or even meaningful, category. At the very least, we need to establish what the category means other than "created by namedtuple() factory function".