
On 7 August 2015 at 06:35, Wes Turner <wes.turner@gmail.com> wrote:
On Aug 6, 2015 3:03 PM, "Guido van Rossum" <guido@python.org> wrote:
Unfortunately, all spellings that require calling locals() are wrong.
Is this where the potential source of surprising error is?
Yes - it's what creates the temptation for people to use sys._getframe() to hide the locals() calls, and either approach hides the name references from lexical analysers (hence Barry's comment about false alarms regarding "unused locals" when scanning code that uses flufl.il8n). When people are being tempted to write code that is too clever for a computer to easily follow without executing it, that's cause for concern (being able to *write* such code is useful for exploratory purposes, but it's also the kind of thing that's desirable to factor out as a code base matures). When it comes to name based string interpolation, the current "correct" approach (which even computers can read) requires duplicating the name references explicitly in constructs like: print("This interpolates {a} and {b}".format(a=a, b=b)) Which doesn't fare well for readability when compared to sys._getframe() based implicit approaches like flufl.il8n's: print(_("This interpolates $a and $b")) The f-string proposal provides a way to write the latter kind of construct in a more explicit way that even computers can learn to read (without executing it). Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia