On Sat, Oct 16, 2021 at 09:19:26AM -0400, Erik Demaine wrote: > To me (a mathematician), the existence of this magic in def, class, import, > etc. is a sign that this is indeed useful functionality. As a fan of > first-class language features, it definitely makes me wonder whether it > could be generalized.
Obviously it is useful, because we have four major uses for it: imports, classes, functions and decorators. And I can think of at least two minor uses: the three argument form of type(), and namedtuple. The question is, are any additional uses worth the effort and potential ugliness of generalising it? Not every generalisation is worth it. Sometimes you can overgeneralise. https://www.joelonsoftware.com/2001/04/21/dont-let-architecture-astronauts-scare-you/ Until we have some compelling use-cases beyond the Big Four, I think this is a case of YAGNI. https://www.martinfowler.com/bliki/Yagni.html I've been thinking about use-cases for this feature for literally *years*, I've even got a handful of rough notes for a proto-PEP written down. To my embarrassment, today was the first time I realised that imports are also an example of this feature. So it is possible that there are many great use-cases for this and I just can't see them. > But I'm not sure what the best mechanism is. The mechanism is probably easy, if built into the compiler. When the compiler sees something that looks like a binding operation: target = expression it knows what the target is. If the expression contains some magic token, the compiler can substitute the target as a string for the magic token. (There is at least one other possible solution.) So the implementation is probably easy. It is the design that is hard, and the justification lacking. -- Steve _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/XVKKXFEI6ACCSECTTUYPVZ6KFU4ZACGE/ Code of Conduct: http://python.org/psf/codeofconduct/