Re: [Python-Dev] PEP 567 pre v3

2018-01-12 Thread Guido van Rossum
I think we've debated the design of ContextVar and default values enough. Regardless of the philosophical questions around "what is a variable", I agree that Yury's current design is right, so let's move on to other topics (if there are any). On Thu, Jan 11, 2018 at 12:55 AM, Paul Moore wrote: >

Re: [Python-Dev] PEP 567 pre v3

2018-01-11 Thread Paul Moore
On 11 January 2018 at 07:39, Chris Jerdonek wrote: > But to your question, like it or not, I think the API encourages this > way of thinking because the get() method is on the ContextVar itself, > and so it's the ContextVar which is doing the looking up rather than > just fulfilling the role of a

Re: [Python-Dev] PEP 567 pre v3

2018-01-10 Thread Chris Jerdonek
On Wed, Jan 10, 2018 at 10:58 PM, Yury Selivanov wrote: > On Thu, Jan 11, 2018 at 10:35 AM, Chris Jerdonek > wrote: >> On Mon, Jan 8, 2018 at 11:02 PM, Nathaniel Smith wrote: >>> Right now, the set of valid states for a ContextVar are: it can hold >>> any Python object, or it can be undefined. H

Re: [Python-Dev] PEP 567 pre v3

2018-01-10 Thread Yury Selivanov
On Thu, Jan 11, 2018 at 10:35 AM, Chris Jerdonek wrote: > On Mon, Jan 8, 2018 at 11:02 PM, Nathaniel Smith wrote: >> Right now, the set of valid states for a ContextVar are: it can hold >> any Python object, or it can be undefined. However, the only way it >> can be in the "undefined" state is in

Re: [Python-Dev] PEP 567 pre v3

2018-01-10 Thread Yury Selivanov
On Thu, Jan 11, 2018 at 10:39 AM, Ethan Furman wrote: > On 01/10/2018 10:23 PM, Yury Selivanov wrote: [..] >> Therefore I'm still in favour of keeping the current PEP 567 >> behaviour. > > > To be clear: We'll now be able to specify a default when we create the > variable, but we can also leave i

Re: [Python-Dev] PEP 567 pre v3

2018-01-10 Thread Ethan Furman
On 01/10/2018 10:23 PM, Yury Selivanov wrote: On Thu, Jan 11, 2018 at 4:44 AM, Nathaniel Smith wrote: It may have gotten lost in that email, but my actual favorite approach is that we make the signatures: ContextVar(name, *, initial_value) # or even (*, name, initial_value) ContextVar.get()

Re: [Python-Dev] PEP 567 pre v3

2018-01-10 Thread Chris Jerdonek
On Mon, Jan 8, 2018 at 11:02 PM, Nathaniel Smith wrote: > Right now, the set of valid states for a ContextVar are: it can hold > any Python object, or it can be undefined. However, the only way it > can be in the "undefined" state is in a new Context where it has never > had a value; once it leave

Re: [Python-Dev] PEP 567 pre v3

2018-01-10 Thread Yury Selivanov
On Thu, Jan 11, 2018 at 4:44 AM, Nathaniel Smith wrote: [..] > It may have gotten lost in that email, but my actual favorite approach > is that we make the signatures: > > ContextVar(name, *, initial_value) # or even (*, name, initial_value) > ContextVar.get() > ContextVar.set(value) > > so that

Re: [Python-Dev] PEP 567 pre v3

2018-01-10 Thread Nick Coghlan
On 11 January 2018 at 10:44, Nathaniel Smith wrote: > It may have gotten lost in that email, but my actual favorite approach > is that we make the signatures: > > ContextVar(name, *, initial_value) # or even (*, name, initial_value) > ContextVar.get() > ContextVar.set(value) > > so that when you

Re: [Python-Dev] PEP 567 pre v3

2018-01-10 Thread Nathaniel Smith
On Tue, Jan 9, 2018 at 3:41 AM, Yury Selivanov wrote: > On Tue, Jan 9, 2018 at 11:02 AM, Nathaniel Smith wrote: >> Right now, the set of valid states for a ContextVar are: it can hold >> any Python object, or it can be undefined. However, the only way it >> can be in the "undefined" state is in a

Re: [Python-Dev] PEP 567 pre v3

2018-01-09 Thread Guido van Rossum
There are too many words here for me to follow. I'll wait a few days and then hopefully there's a new proposal that you are all in agreement with, or there are two brief alternatives that I have to choose between. On Tue, Jan 9, 2018 at 7:41 AM, Yury Selivanov wrote: > By default, threading.loca

Re: [Python-Dev] PEP 567 pre v3

2018-01-09 Thread Yury Selivanov
By default, threading.local raises an AttributeError (unless you subclass it.) Similar to that and to NameErrors, I think it's a good idea for ContextVars to raise a LookupError if a variable was not explicitly set. Yury On Tue, Jan 9, 2018 at 7:15 PM Victor Stinner wrote: > 2018-01-09 12:41

Re: [Python-Dev] PEP 567 pre v3

2018-01-09 Thread Victor Stinner
2018-01-09 12:41 GMT+01:00 Yury Selivanov : > But I'd be -1 on making all ContextVars have a None default > (effectively have a "ContextVar.get(default=None)" signature. This > would be a very loose semantics in my opinion. Why do you think that it's a loose semantics? For me ContextVar/Context ar

Re: [Python-Dev] PEP 567 pre v3

2018-01-09 Thread Yury Selivanov
On Tue, Jan 9, 2018 at 11:02 AM, Nathaniel Smith wrote: > On Mon, Jan 8, 2018 at 11:34 AM, Yury Selivanov > wrote: >> 1. Proposal: ContextVar has default set to None. >> >> From the typing point of view that would mean that if a context >> variable is declared without an explicit default, its ty

Re: [Python-Dev] PEP 567 pre v3

2018-01-08 Thread Nathaniel Smith
On Mon, Jan 8, 2018 at 11:34 AM, Yury Selivanov wrote: > 1. Proposal: ContextVar has default set to None. > > From the typing point of view that would mean that if a context > variable is declared without an explicit default, its type would be > Optional. E.g. say we have a hypothetical web frame

Re: [Python-Dev] PEP 567 pre v3

2018-01-08 Thread Guido van Rossum
When I +1'ed Yury's message I forgot about this issue. I actually prefer the current PEP 567 version -- .get() raises an error if there's no default on the ContextVar, and .get(None) returns None if there's no default. The idea here is that by far the most common use will be .get(), so it should be

Re: [Python-Dev] PEP 567 pre v3

2018-01-08 Thread Nick Coghlan
On 9 January 2018 at 05:34, Yury Selivanov wrote: > Maybe we can rename ContextVar.get() to ContextVar.lookup()? This > would help to avoid potential confusion between Context.get() and > ContextVar.get(). I think this would also tie in nicely with the PEP 568 draft, where "ContextVar.lookup()"

Re: [Python-Dev] PEP 567 pre v3

2018-01-08 Thread Guido van Rossum
I am +1 on everything Yury says here. On Mon, Jan 8, 2018 at 11:34 AM, Yury Selivanov wrote: > Hi, > > Thanks to everybody participating in the PEP 567 discussion! I want > to summarize a few topics to make sure that we are all on the same > page (and maybe provoke more discussion). > > > 1. Pr

Re: [Python-Dev] PEP 567 pre v3

2018-01-08 Thread Victor Stinner
Hum, now I'm confused. I was probably confused by ContextVar.get() differences with Context.get(). It's fine if it behaves with a dict. Victor Le 9 janv. 2018 12:02 AM, "Nathaniel Smith" a écrit : > On Mon, Jan 8, 2018 at 2:35 PM, Victor Stinner > wrote: > > ctx[var] raises an exception but c

Re: [Python-Dev] PEP 567 pre v3

2018-01-08 Thread Nathaniel Smith
On Mon, Jan 8, 2018 at 2:35 PM, Victor Stinner wrote: > ctx[var] raises an exception but ctx.get(var) returns None in such case. My > point is just that Context.get() behaves differently than dict.get(). If > dict[key] raises, I expect that dict.get() raises too and that I have to > write explicit

Re: [Python-Dev] PEP 567 pre v3

2018-01-08 Thread Victor Stinner
Le 8 janv. 2018 8:36 PM, "Yury Selivanov" a écrit : 2. Context.__contains__, Context.__getitem__ and ContexVar.default So if we keep the current PEP 567 behaviour w.r.t. defaults, ContextVar.get() might return a different value from Context.get(): v = ContextVar('v', default=42) ctx = c

[Python-Dev] PEP 567 pre v3

2018-01-08 Thread Yury Selivanov
Hi, Thanks to everybody participating in the PEP 567 discussion! I want to summarize a few topics to make sure that we are all on the same page (and maybe provoke more discussion). 1. Proposal: ContextVar has default set to None. >From the typing point of view that would mean that if a context