Re: [Python-Dev] Whatever happened to 'nonlocal x = y'?

2018-01-05 Thread Benjamin Peterson
On Fri, Jan 5, 2018, at 01:57, Nathaniel Smith wrote: > Was this just an oversight, or did it get rejected at some point and > no-one remembered to update that PEP? There was an implementation https://bugs.python.org/issue4199. But several years ago, we again reached the conclusion that the fe

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Nathaniel Smith
On Fri, Jan 5, 2018 at 2:43 PM, Chris Jerdonek wrote: > One thing that I think could be contributing to confusion around the > proposed API is that there is a circular relationship between Context > and ContextVar, e.g. ContextVar.get() does a lookup in the current > Context with "self" (the Conte

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Nathaniel Smith
On Thu, Jan 4, 2018 at 4:48 PM, Guido van Rossum wrote: > Your suggestions sound reasonable, but we are now running into a logistical > problem -- I don't want to decide this unilaterally but Yury is on vacation > until Jan 15. That gives us at most 2 weeks for approval of the PEP and > review + c

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Elvis Pranskevichus
On Friday, January 5, 2018 5:43:24 PM EST Chris Jerdonek wrote: > Is there a reason ContextVar needs to be exposed publicly at all? For > example, the API could use string keys like contextvars.get(name) or > Context.get(name) (class method). There could be separate functions > to initialize keys

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Nathaniel Smith
On Thu, Jan 4, 2018 at 3:18 PM, Nathaniel Smith wrote: > I think the fix is a little bit cumbersome, but straightforward, and > actually *simplifies* caching. [...] > And then the caching in get() becomes: > > def get(self): > if tstate->current_context != self->last_context: > # Updat

Re: [Python-Dev] Whatever happened to 'nonlocal x = y'?

2018-01-05 Thread Paul Moore
On 5 January 2018 at 23:02, Guido van Rossum wrote: > I don't like those examples -- "nonlocal foo = bar" sounds like bar is used > as the *initializer*, but it actually is just an assignment that overwrites > the actual initial value. IMO those shouldn't be combined. That was my immediate reacti

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Guido van Rossum
On Fri, Jan 5, 2018 at 2:43 PM, Chris Jerdonek wrote: > On Fri, Jan 5, 2018 at 8:29 AM, Guido van Rossum wrote: > > On Fri, Jan 5, 2018 at 2:05 AM, Victor Stinner > > > wrote: > >> > >> Currently, Context.get(var) returns None when "var in context" is false. > >> That's surprising and different

Re: [Python-Dev] Whatever happened to 'nonlocal x = y'?

2018-01-05 Thread Guido van Rossum
I don't like those examples -- "nonlocal foo = bar" sounds like bar is used as the *initializer*, but it actually is just an assignment that overwrites the actual initial value. IMO those shouldn't be combined. On Fri, Jan 5, 2018 at 2:59 PM, Nathaniel Smith wrote: > On Fri, Jan 5, 2018 at 7:47

Re: [Python-Dev] Whatever happened to 'nonlocal x = y'?

2018-01-05 Thread Nathaniel Smith
On Fri, Jan 5, 2018 at 7:47 AM, Guido van Rossum wrote: > I don't recall (though someone with more time might find the discussion in > the archives or on the tracker). It was never implemented and I think it > shouldn't be. So we might as well update the PEP. It wouldn't be > particularly useful,

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Chris Jerdonek
On Fri, Jan 5, 2018 at 8:29 AM, Guido van Rossum wrote: > On Fri, Jan 5, 2018 at 2:05 AM, Victor Stinner > wrote: >> >> Currently, Context.get(var) returns None when "var in context" is false. >> That's surprising and different than var.get(), especially when var has a >> default value. > > I don

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Eric V. Smith
On 1/5/2018 2:11 PM, Eric V. Smith wrote: On 1/5/2018 2:09 PM, Guido van Rossum wrote: I'm normally no big fan of things that take either a class or an instance, but since fields() does this, I think is_dataclass() should to. And that's the name I'd choose. OK on the pseudo-fields. Sounds goo

Re: [Python-Dev] Unique loader per module

2018-01-05 Thread Brett Cannon
Barry and I had a meeting at work today and we decided to go with Nick's idea of using a get_resource_reader(fullname) method on loaders. We aren't going to go with an ABC and simply depend on the method existing as implementing the API (and then returning None if the loader can't handle the specif

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Eric V. Smith
On 1/5/2018 2:09 PM, Guido van Rossum wrote: I'm normally no big fan of things that take either a class or an instance, but since fields() does this, I think is_dataclass() should to. And that's the name I'd choose. OK on the pseudo-fields. Sounds good. I'll open a bpo issue. Eric. On Fri, J

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Guido van Rossum
I'm normally no big fan of things that take either a class or an instance, but since fields() does this, I think is_dataclass() should to. And that's the name I'd choose. OK on the pseudo-fields. On Fri, Jan 5, 2018 at 11:06 AM, Eric V. Smith wrote: > On 1/5/2018 12:58 PM, Guido van Rossum wrote

Re: [Python-Dev] Whatever happened to 'nonlocal x = y'?

2018-01-05 Thread Guido van Rossum
Yeah, but I've changed my mind on this -- I think it's needless added complexity that helps save one line of code in very few use cases. And you don't really think the PEP endorses `nonlocal foo += 1` do you? On Fri, Jan 5, 2018 at 10:48 AM, Random832 wrote: > On Fri, Jan 5, 2018, at 10:47, Guid

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Eric V. Smith
On 1/5/2018 12:58 PM, Guido van Rossum wrote: Hm. I don't know that people will conclude that checking for a dataclass is an anti-pattern. They'll probably just invent a myriad of different hacks like the one you showed. I recommend making it public. I'm trying to track down the original discu

Re: [Python-Dev] Whatever happened to 'nonlocal x = y'?

2018-01-05 Thread Random832
On Fri, Jan 5, 2018, at 10:47, Guido van Rossum wrote: > I don't recall (though someone with more time might find the discussion in > the archives or on the tracker). It was never implemented and I think it > shouldn't be. So we might as well update the PEP. It wouldn't be > particularly useful, si

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Guido van Rossum
Hm. I don't know that people will conclude that checking for a dataclass is an anti-pattern. They'll probably just invent a myriad of different hacks like the one you showed. I recommend making it public. I still worry a bit about ClassVar and InitVar being potentially useful but I concede I have

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Guido van Rossum
Some inline responses to Paul (I snipped everything I agree with). On Wed, Jan 3, 2018 at 3:34 AM, Paul Moore wrote: > On 28 December 2017 at 06:08, Yury Selivanov > wrote: > > This is a second version of PEP 567. > [...] > > > The notion of "current value" deserves special consideration: > > d

[Python-Dev] Summary of Python tracker Issues

2018-01-05 Thread Python tracker
ACTIVITY SUMMARY (2017-12-29 - 2018-01-05) Python tracker at https://bugs.python.org/ To view or respond to any of the issues listed below, click on the issue. Do NOT respond to this message. Issues counts and deltas: open6377 (+22) closed 37871 (+28) total 44248 (+50) Open issues wi

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Guido van Rossum
On Fri, Jan 5, 2018 at 3:10 AM, Paul Moore wrote: > On 5 January 2018 at 11:06, Victor Stinner > wrote: > >> Le 5 janv. 2018 11:42 AM, "Paul Moore" a écrit : > >> """ > >> A Context is a mapping from ContextVar objects to their values. The > >> Context itself exposes the Mapping interface, so c

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Eric V. Smith
On 1/5/2018 11:24 AM, Guido van Rossum wrote: On Fri, Jan 5, 2018 at 5:08 AM, Eric V. Smith > wrote: On 1/2/2018 12:01 AM, Guido van Rossum wrote: Yes, there's a class variable (__dataclass_fields__) that identifies the parent fields. The PEP doesn

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Guido van Rossum
On Fri, Jan 5, 2018 at 2:41 AM, Paul Moore wrote: > On 4 January 2018 at 23:58, Guido van Rossum wrote: > > Do you have a specific proposal for a wording change? PEP 567 describes > > Context as "a read-only mapping, implemented using an immutable > dictionary." > > This sounds all right to me -

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Guido van Rossum
On Fri, Jan 5, 2018 at 2:05 AM, Victor Stinner wrote: > Currently, Context.get(var) returns None when "var in context" is false. > That's surprising and different than var.get(), especially when var has a > default value. > I don't see the problem. Context.get() is inherited from Mapping.get();

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Guido van Rossum
On Fri, Jan 5, 2018 at 5:08 AM, Eric V. Smith wrote: > On 1/2/2018 12:01 AM, Guido van Rossum wrote: > >> Yes, there's a class variable (__dataclass_fields__) that identifies the >> parent fields. The PEP doesn't mention this or the fact that special >> methods (like __repr__ and __init__) can te

Re: [Python-Dev] Whatever happened to 'nonlocal x = y'?

2018-01-05 Thread Guido van Rossum
On Fri, Jan 5, 2018 at 1:57 AM, Nathaniel Smith wrote: > PEP 3104 says: > > """ > A shorthand form is also permitted, in which nonlocal is prepended to > an assignment or augmented assignment: > > nonlocal x = 3 > > The above has exactly the same meaning as nonlocal x; x = 3. (Guido > supports a

Re: [Python-Dev] Concerns about method overriding and subclassing with dataclasses

2018-01-05 Thread Eric V. Smith
On 1/2/2018 12:01 AM, Guido van Rossum wrote: On Mon, Jan 1, 2018 at 8:50 PM, Ethan Smith > wrote: On Mon, Jan 1, 2018 at 5:03 PM, Chris Barker mailto:chris.bar...@noaa.gov>> wrote: On Sat, Dec 30, 2017 at 7:27 AM, Stephen J. Turnbull mailto:turnbu

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Paul Moore
On 5 January 2018 at 11:06, Victor Stinner wrote: >> Le 5 janv. 2018 11:42 AM, "Paul Moore" a écrit : >> """ >> A Context is a mapping from ContextVar objects to their values. The >> Context itself exposes the Mapping interface, so cannot be modified >> directly - to modify the value associated w

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Victor Stinner
You can only modify a context when it's the current context, so using ContextVar.set() in Context.run(). Victor Le 5 janv. 2018 11:42 AM, "Paul Moore" a écrit : On 4 January 2018 at 23:58, Guido van Rossum wrote: > On Thu, Jan 4, 2018 at 9:27 AM, Paul Moore wrote: >> >> On 4 January 2018 at 1

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Paul Moore
On 4 January 2018 at 23:58, Guido van Rossum wrote: > On Thu, Jan 4, 2018 at 9:27 AM, Paul Moore wrote: >> >> On 4 January 2018 at 15:56, Guido van Rossum wrote: >> > It was get_context() in an earlier version of PEP 567. We changed it to >> > copy_context() believing that that would clarify tha

Re: [Python-Dev] PEP 567 v2

2018-01-05 Thread Victor Stinner
Currently, Context.get(var) returns None when "var in context" is false. That's surprising and different than var.get(), especially when var has a default value. Code: --- import contextvars name = contextvars.ContextVar('name', default='victor') context = contextvars.copy_context() print(name in

[Python-Dev] Whatever happened to 'nonlocal x = y'?

2018-01-05 Thread Nathaniel Smith
PEP 3104 says: """ A shorthand form is also permitted, in which nonlocal is prepended to an assignment or augmented assignment: nonlocal x = 3 The above has exactly the same meaning as nonlocal x; x = 3. (Guido supports a similar form of the global statement [24].) """ The PEP metadata says it