[Python-ideas] Re: Namespace context managers

2019-07-28 Thread Ricky Teachey
> > > It’s not clear to me whether people want a module-like, class-like, or > > function-like namespace here > > I'm not going to speak for "people", but for me, I think that the answer > should be obvious: it is module-like. > I was also talking 100% about module-like namespaces, and I also am

[Python-ideas] Re: Namespace context managers

2019-07-28 Thread Ryan Gonzalez
I feel like this could have some interesting side uses (typing on mobile so ignore the crappy indentation): with Namespace('a'): x = 1 y = 2 print(a.__dict__) # we now have a dict The GN build system flat-out has no dictionary / mapping type in favor of scopes like this. On Sun, Jul 28,

[Python-ideas] Re: Namespace context managers

2019-07-28 Thread Steven D'Aprano
On Fri, Jul 26, 2019 at 10:52:46AM -0400, Calvin Spealman wrote: > Let's say you do this or any of the variants suggested... What does this do? > > a = {"foo": 1} > b = {} > with a: > with b: > foo = 0 Re-writing that to my suggested version: with namespace("a") as a: with

[Python-ideas] Re: Namespace context managers

2019-07-28 Thread Steven D'Aprano
On Fri, Jul 26, 2019 at 01:37:29PM -0700, Andrew Barnert wrote: > It’s not clear to me whether people want a module-like, class-like, or > function-like namespace here, but I do think it’s probably exactly one > of those three. And it’ll be a lot easier to define and implement—and > for

[Python-ideas] Fwd: Re: Universal parsing library in the stdlib to alleviate security issues

2019-07-28 Thread Nam Nguyen
Forward to the list because Abusix had blocked google.com initially. Nam -- Forwarded message - From: Nam Nguyen Date: Sun, Jul 28, 2019 at 10:18 AM Subject: Re: [Python-ideas] Re: Universal parsing library in the stdlib to alleviate security issues To: Sebastian Kreft Cc: Paul

[Python-ideas] Re: Utilities for easier debugging

2019-07-28 Thread Kyle Stanley
Steven D'Aprano wrote: > By the way, you know that Python has a read-only global variable that > tells you whether you are in debug mode? You can write a function to > display anything you like, and wrap it in a test like this: > if __debug__: > display(locals()) Oh interesting, I wasn't

[Python-ideas] Re: Utilities for easier debugging

2019-07-28 Thread Steven D'Aprano
On Sun, Jul 28, 2019 at 01:19:38AM -0400, James Lu wrote: > Minimal strawman proposal. New keyword debug. > > debug EXPRESSION > > Executes EXPRESSION when in debug mode. That's what assert does, in part. Since print is now a function, not a statement, you can do this: assert

[Python-ideas] Fwd: Utilities for easier debugging

2019-07-28 Thread James Lu
Sent from my iPhone Begin forwarded message: > From: James Lu > Date: July 28, 2019 at 6:22:11 PM EDT > To: Andrew Barnert > Subject: Re: [Python-ideas] Utilities for easier debugging > > >> On Jul 28, 2019, at 4:26 PM, Andrew Barnert wrote: >> >> This would break iPython’s improved

[Python-ideas] Fwd: Utilities for easier debugging

2019-07-28 Thread James Lu
Sent from my iPhone Begin forwarded message: > From: James Lu > Date: July 28, 2019 at 6:21:04 PM EDT > To: Andrew Barnert > Subject: Re: [Python-ideas] Utilities for easier debugging > > >> On Jul 28, 2019, at 4:26 PM, Andrew Barnert wrote: >> >> Why not just allow anything that’s valid

[Python-ideas] Fwd: Utilities for easier debugging

2019-07-28 Thread James Lu
Sent from my iPhone Begin forwarded message: > From: James Lu > Date: July 28, 2019 at 6:22:11 PM EDT > To: Andrew Barnert > Subject: Re: [Python-ideas] Utilities for easier debugging > > >> On Jul 28, 2019, at 4:26 PM, Andrew Barnert wrote: >> >> This would break iPython’s improved

[Python-ideas] Fwd: Utilities for easier debugging

2019-07-28 Thread James Lu
Sent from my iPhone Begin forwarded message: > From: James Lu > Date: July 28, 2019 at 6:21:04 PM EDT > To: Andrew Barnert > Subject: Re: [Python-ideas] Utilities for easier debugging > > >> On Jul 28, 2019, at 4:26 PM, Andrew Barnert wrote: >> >> Why not just allow anything that’s valid

[Python-ideas] Fwd: Utilities for easier debugging

2019-07-28 Thread James Lu
Sent from my iPhone Begin forwarded message: > From: James Lu > Date: July 28, 2019 at 6:23:06 PM EDT > To: Andrew Barnert > Subject: Re: [Python-ideas] Utilities for easier debugging > > >> On Jul 28, 2019, at 4:26 PM, Andrew Barnert wrote: >> >> You want this added to every module’s

[Python-ideas] Re: Utilities for easier debugging

2019-07-28 Thread Andrew Barnert via Python-ideas
On Jul 27, 2019, at 22:19, James Lu wrote: > > Minimal strawman proposal. New keyword debug. > > debug EXPRESSION > > Executes EXPRESSION when in debug mode. You really mean expression, not statement here? That doesn’t seem very useful. Sure, some expressions are used for side effects, but most

[Python-ideas] Re: Utilities for easier debugging

2019-07-28 Thread Dominik Vilsmeier
James Lu wrote: > Minimal strawman proposal. New keyword debug. > debug EXPRESSION > Executes EXPRESSION when in debug mode. > debug context > Prints all the variables of the enclosing closure and all the variable names > accessed > within that block. For example, if in foo you access the global

[Python-ideas] Re: Utilities for easier debugging

2019-07-28 Thread Dominik Vilsmeier
James Lu wrote: > Minimal strawman proposal. New keyword debug. > debug EXPRESSION > Executes EXPRESSION when in debug mode. > debug context > Prints all the variables of the enclosing closure and all the variable names > accessed > within that block. For example, if in foo you access the global

[Python-ideas] Re: for ... except, with ... except

2019-07-28 Thread Ethan Furman
[redirecting back to the list] On 07/27/2019 09:38 PM, James Lu wrote: On Jul 27, 2019, at 12:44 PM, Ethan Furman wrote: Sure, folks /know/ what it means, but it's a common bug because it doesn't read as "if some_var is assigned 7" but as "if some_var is equal to 7". That’s a straw man- a

[Python-ideas] Utilities for easier debugging

2019-07-28 Thread James Lu
Minimal strawman proposal. New keyword debug. debug EXPRESSION Executes EXPRESSION when in debug mode. debug context Prints all the variables of the enclosing closure and all the variable names accessed within that block. For example, if in foo you access the global variable spam, spam

[Python-ideas] Re: Add a "partial with placeholders" function to the functools module

2019-07-28 Thread Dominik Vilsmeier
An extension of `partial` itself would indeed be a clean solution (+ backwards compatibility), my concern was just that when most people are still using it in the "traditional" way (for example partializing via keyword), that the additional checks for `SKIP` introduce an unnecessary overhead

[Python-ideas] Re: Add a "partial with placeholders" function to the functools module

2019-07-28 Thread Dominik Vilsmeier
Indeed it is important to not only consider the potential use cases for such a placeholder function, but to consider the cases that go beyond of what a lambda can do. A lambda is always a good option if it is used as a "single-serving" function, i.e. one that is only relevant locally where it