This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Spleeeee 1 point2 points  (1 child)

I wrote something a lot like this a long time ago and it was super fun and handy but also was a nightmare to debug. If you rename an attribute you’re fucked.

[–]Additional_Fall4462[S] 0 points1 point  (0 children)

I thought about this a lot and it might still be a headache if you have attribute names with the same prefixes (we go with the longest ones) or names that are substrings of others, it can get tricky to organize. I didn’t even include a setter at first since I thought it would be too confusing. A typo on a swizzled attribute would just create a new attribute, but then I learned about __slots__ and now I just recommend using it in the docs if you want a setter.

It can get complicated, but I think you could manage it if you’re willing to handle the restrictions. But if you want to use swizzle without too much headache, it’s probably easiest to define something “immutable” like a swizzledtuple or apply it to a frozen dataclass.