Python 3.6 and objc_util syntax
When we were discussing a cleaner
objc_utilsyntax a few months ago, the suggestion of using kwargs was rejected because there as no way to guarantee the order. However, look at this from the Python 3.6 release notes!
**kwargsin a function signature is now guaranteed to be an insertion-order-preserving mapping.
This is from PEP 468
Unless I'm mistaken, this would enable that syntax.
WOOO! This change has been long overdue. Been waiting for this PEP. Though it's probably going to be a while until 3.6 is out.
Though this still doesn't allow calling all Objective-C methods using kwarg syntax. Some have duplicate selector parts (I think
performSelector:withObject:withObject:is a real
NSObjectmethod) and apparently selector parts can be empty too (like
Maybe it can be used for most cases. I'd really like this syntax
Python 3.6 is already available as a Beta on the standard platforms and the release is due before Christmas. Of course, it will take a bit longer to get 3.6 in Pythonista.
@filippocld Don't get me wrong, it will work for almost all cases. Selectors with parts with the same name are quite rare, and ones with "unnamed" parts are basically nonexistant (so far I've only seen them in old deprecated classes).
Also I think you can already use this type of syntax in the current Pythonista betas, it's just a bit slower, because
objc_utilhas to try all possible orderings of the kwarg names to find out what selector has to be used.
Yeah, it takes a bit more but it's usable. Let's hope for some speed in the future :-)