From: Juan Nunez-I. <jni...@gm...> - 2015-05-14 02:30:20
|
Thanks Tom! Absolutely fascinating! I was trying to grok this and thinking, "but what if we want 'or' to return a value that will later be used as a conditional, surely it should return bool?" But of course whatever it returns will be correctly interpreted as a bool in a conditional context! Delayed/lazy bool casting, in a sense. Very clever indeed. There's quite a few places where this would make my code quite a bit cleaner! =) Thanks again! Juan. On Thu, May 14, 2015 at 12:21 PM, Thomas Caswell <tca...@gm...> wrote: > The `a or b` syntax evaluates if a is 'trueish' and if so returns a if not > returns b so `c = None or {}` -> c == {} but `c = {'a': 1} or {}` -> c == > {'a': 1} > > See > https://docs.python.org/3.5/reference/expressions.html#grammar-token-or_test > for the docs on or. and works almost the same, but returns a if a is False > and b in a is True. > > In the grammar for calls it should be looking for thing like "'**' > expression" which means in the parsing anything that is part of the > expression gets evaluated before the unpacking of the mapping. If you > chase far enough back in the grammar an 'or_test' is an 'expression' (I may > be butchering the terminology here, only just learned how lexing/parsing > works a few weeks ago) so it should be fully evaluated before trying to > unpack. > > See https://docs.python.org/3.5/reference/expressions.html#calls for the > official docs. > > I suspect the source of this bug is that the grammar is getting rearranged > a bit to allow for things like d = {**other_dict, 'x':6} and b = (*a, *c) > to work as expected and something did not get changed quite right. > > Tom > > On Wed, May 13, 2015 at 8:33 PM Juan Nunez-Iglesias <jni...@gm...> > wrote: > >> Fascinating! Can you "unpack" (heh) that error for us mere mortals? In >> particular: >> >> - never seen that "or" syntax before... Is it coercing both expressions >> as bool, or is it evaluating to left if bool(left) evaluates to True, else >> to right? >> - Why do you expect the second expression to work? Is ** supposed to have >> lower preference than "or"? (Which seems weird to me.) >> >> Thanks! >> >> Juan. >> >> On Thu, May 14, 2015 at 5:08 AM, Thomas Caswell <tca...@gm...> >> wrote: >> >>> >>> The failures on python nightly are currently due to a bug in python ( >>> http://bugs.python.org/issue24176) >>> >>> Tom >>> >>> >>> ------------------------------------------------------------------------------ >>> One dashboard for servers and applications across Physical-Virtual-Cloud >>> Widest out-of-the-box monitoring support with 50+ applications >>> Performance metrics, stats and reports that give you Actionable Insights >>> Deep dive visibility with transaction tracing using APM Insight. >>> http://ad.doubleclick.net/ddm/clk/290420510;117567292;y >>> _______________________________________________ >>> Matplotlib-devel mailing list >>> Mat...@li... >>> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel >>> >>> >> >> ------------------------------------------------------------------------------ >> One dashboard for servers and applications across Physical-Virtual-Cloud >> Widest out-of-the-box monitoring support with 50+ applications >> Performance metrics, stats and reports that give you Actionable Insights >> Deep dive visibility with transaction tracing using APM Insight. >> http://ad.doubleclick.net/ddm/clk/290420510;117567292;y >> _______________________________________________ >> Matplotlib-devel mailing list >> Mat...@li... >> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel >> > |