> Maybe borrowing a word from a different language—record or datatype or something—would avoid that problem?

Hmm, I don't think "record" would work. The terms "record", "struct", and "tuple" are far too synonymous with one another (https://en.wikipedia.org/wiki/Record_(computer_science)). This term would have to be something that would apply to namedtuples (or similarly structured datatype) without applying to tuples as well.

Perhaps something like "associative container" might be more viable? This would apply to any type that could be directly converted to or represented as a dictionary.

On Wed, Oct 16, 2019 at 8:18 PM Andrew Barnert via Python-ideas <python-ideas@python.org> wrote:
On Oct 16, 2019, at 13:48, Steven D'Aprano <steve@pearwood.info> 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?
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/SCOXP4BYJ4HO4I74E7WPMRCJ5TLDUD4B/
Code of Conduct: http://python.org/psf/codeofconduct/