-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add list_property, and other property cleanups #148
Conversation
Somewhat related question: the dict-like |
A tuple isn't "just an immutable list"; there are other semantic details that are significant. If we need a "readonly list", then we should create one by creating a custom class that allows list-like access, but doesn't expose modification properties (or exposes them in a way that does trigger validation - but readonly seems like a much easier option).
I think this becomes a moot point once we're using a readonly-list for storage.
That makes sense to me.
I appreciate that in the If we are going to remove duplicates, we need to ensure that "first usage" order is preserved -
These all make sense to me. |
I realize that lists are customarily used for arbitrary-length collections of more-or-less homogeneous items, and tuples for fixed-length collections where position matters... but even the Python docs say "Tuples are also used for cases where an immutable sequence of homogeneous data is needed (such as allowing storage in a set." I'll subclass UserList and overwrite all fifteen mutable methods if you really do prefer it, it just seems like reinventing a wheel. (I did think of the idea of a self-validating list, but I have a hard time imagining it wouldn't be more trouble than it would be worth.)
The de-duplication is already preserving order, but no, I guess there's no real reason we need it. I'll yank it out. Any opinion on the |
Reasonable people can disagree with the Python docs :-P As for subclassing - It sounds like a proxy API might be easier. I can't remember if this was a PR from you or someone else, but subclassing a primitive type means you can accidentally inherit capabilities (sometimes with hillarious consequences [see footnote 1]) - we only really need
Yeah - we can shave that yak if/when it starts looking necessary.
It wasn't a deliberate choice AFAIR. If we can expand the usage to work with all aliases, I can't think of any reason not to. [1] I've actually worked on the system described in that anecdote (JSAF), and... I don't entirely believe the explanation given by the DSTO employee. I don't remember "beachballs" being a default anything in JSAF, and I accidentally made an aircraft carrier travel at mach 2 because of a subclassing error. Object LISP: not even once, my friends :-) |
I think this may legit be the first time I've ever found myself on this side of a disagreement over technical correctness vs. pragmatism. It's a strange experience. 🤣
I added
Don't worry, I won't tell the Inquisitors.
Make that happen by accident in Toga and then I'll really be impressed. 😉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely on the right track; a couple of minor issues flagged inline.
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
11c4222
to
2c08ea0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - a couple of really minor cosmetic suggestions, and I think we're there!
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
Co-authored-by: Russell Keith-Magee <russell@keith-magee.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - two last minute issues I picked up, but this is good to go! Thanks for the PR!
I'm still working on
composite_property
, but there's enough going on here I decided to split it into separate PRs.First of all, I've made some API decisions that I'm open to being talked out of:
style.series_prop.append("something")
and completely bypass validation.list_property
toseries_property
. Could also be... sequence? Something else?None
: it raises an error and suggests usingdel
to unset the property.I've also made some other tweaks to the existing code:
directional_property
, from when I was giving it too many brains. They're now removed.BaseStyle
's internal methods and noticed several I could simplify, particularly from usingin
now that it's defined.__init_subclass__
to give each style subclass a direct reference to its set of properties, so it doesn't have to index into the overall dict over and over again. I like how it makes things cleaner, but I'll understand and undo if you feel like this is a bit too much fiddly magic. (It would be cool if this could just replace the dict, but__init_subclass__
isn't called until after all the properties are initialized and named.)PR Checklist: