On Oct 16, 2019, at 13:48, Steven D'Aprano email@example.com wrote:
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".
I think what he’s looking for is the adjective that goes with the quasi-word “struct” as used in C, and in Python’s ctypes and C API. The type name “Struct” isn’t bad here, but the adjective “structural” has to many other connotations.
Maybe borrowing a word from a different language—record or datatype or something—would avoid that problem?
But I think the big problem here is the one you identified. We can make a list of things that are “like C structs” (which should probably include structseq builtin/extension types, ctypes.Struct, third-party stuff like attrs and maybe numpy structured dtypes, in addition to namedtuple and dataclass). Maybe we could even come up with a way to either programmatically detect them or get them all registered. But what would you do with it?
It might be useful for reflection if there were a way to enumerate all of the “struct fields” that worked for all “struct types”, but there isn’t.
Also, while all of these things _allow_ you to define a plain-old-data struct, none of them _require_ it. You can have a dataclass, namedtuple subclass, structseq, ctypes.Struct, etc. that has all kinds of fancy behavior, including not just methods, but @property and weird __new__ overloads and even custom __getattribute__. And of course you can just as easily define a regular old class and then use it as a plain-old-data struct. So, would this even be useful as a hint, much less a guarantee, of anything?