Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-16 Thread Jeff Hardy
On Sun, Oct 14, 2018 at 12:15 PM Jeff Allen wrote: > > > On 10/10/2018 00:06, Steven D'Aprano wrote: > > On Tue, Oct 09, 2018 at 09:37:48AM -0700, Jeff Hardy wrote: > > ... > > From an alternative implementation point of view, CPython's behaviour > *is* the spec. Practicality beats purity and all

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-14 Thread Jeff Allen
On 10/10/2018 00:06, Steven D'Aprano wrote: On Tue, Oct 09, 2018 at 09:37:48AM -0700, Jeff Hardy wrote: ... From an alternative implementation point of view, CPython's behaviour *is* the spec. Practicality beats purity and all that. Are you speaking on behalf of all authors of alternate

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-12 Thread Steven D'Aprano
On Thu, Oct 11, 2018 at 01:27:08PM -0400, Chris Barker - NOAA Federal via Python-Dev wrote: > > On the server side, the application could be doing something like > > assuming that the kwargs are e.g. column names > > This is exactly a use-case for non-identifier strings in kwargs. Why not just

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-12 Thread Samuele Pedroni
On Thu, Oct 4, 2018 at 10:58 AM Steven D'Aprano wrote: > While keyword arguments have to be identifiers, using **kwargs allows > arbitrary strings which aren't identifiers: > > py> def spam(**kwargs): > ... print(kwargs) > ... > py> spam(**{"something arbitrary": 1, '\n': 2}) > {'something

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-11 Thread Chris Barker - NOAA Federal via Python-Dev
> On the server side, the application could be doing something like > assuming that the kwargs are e.g. column names This is exactly a use-case for non-identifier strings in kwargs. The rules for valid field names could very well be different than Python’s rules. The kwargs implementation is not

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-10 Thread Serhiy Storchaka
10.10.18 05:12, Benjamin Peterson пише: On Tue, Oct 9, 2018, at 17:14, Barry Warsaw wrote: On Oct 9, 2018, at 16:21, Steven D'Aprano wrote: On Tue, Oct 09, 2018 at 10:26:50AM -0700, Guido van Rossum wrote: My feeling is that limiting it to strings is fine, but checking those strings for

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-10 Thread Chris Jerdonek
On Tue, Oct 9, 2018 at 8:55 PM Guido van Rossum wrote: > On Tue, Oct 9, 2018 at 7:49 PM Chris Jerdonek > wrote: >> On Tue, Oct 9, 2018 at 7:13 PM Benjamin Peterson wrote: >> > Can anyone think of a situation where it would be advantageous for an >> > implementation to reject non-identifier

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-09 Thread Glenn Linderman
On 10/9/2018 7:46 PM, Chris Jerdonek wrote: On Tue, Oct 9, 2018 at 7:13 PM Benjamin Peterson wrote: On Tue, Oct 9, 2018, at 17:14, Barry Warsaw wrote: On Oct 9, 2018, at 16:21, Steven D'Aprano wrote: On Tue, Oct 09, 2018 at 10:26:50AM -0700, Guido van Rossum wrote: My feeling is that

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-09 Thread Guido van Rossum
On Tue, Oct 9, 2018 at 7:49 PM Chris Jerdonek wrote: > On Tue, Oct 9, 2018 at 7:13 PM Benjamin Peterson > wrote: > > On Tue, Oct 9, 2018, at 17:14, Barry Warsaw wrote: > > > On Oct 9, 2018, at 16:21, Steven D'Aprano wrote: > > > > > > > > On Tue, Oct 09, 2018 at 10:26:50AM -0700, Guido van

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-09 Thread Chris Jerdonek
On Tue, Oct 9, 2018 at 7:13 PM Benjamin Peterson wrote: > On Tue, Oct 9, 2018, at 17:14, Barry Warsaw wrote: > > On Oct 9, 2018, at 16:21, Steven D'Aprano wrote: > > > > > > On Tue, Oct 09, 2018 at 10:26:50AM -0700, Guido van Rossum wrote: > > >> My feeling is that limiting it to strings is

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-09 Thread Benjamin Peterson
On Tue, Oct 9, 2018, at 17:14, Barry Warsaw wrote: > On Oct 9, 2018, at 16:21, Steven D'Aprano wrote: > > > > On Tue, Oct 09, 2018 at 10:26:50AM -0700, Guido van Rossum wrote: > >> My feeling is that limiting it to strings is fine, but checking those > >> strings for resembling identifiers is

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-09 Thread Guido van Rossum
On Tue, Oct 9, 2018 at 5:17 PM Barry Warsaw wrote: > On Oct 9, 2018, at 16:21, Steven D'Aprano wrote: > > > > On Tue, Oct 09, 2018 at 10:26:50AM -0700, Guido van Rossum wrote: > >> My feeling is that limiting it to strings is fine, but checking those > >> strings for resembling identifiers is

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-09 Thread Barry Warsaw
On Oct 9, 2018, at 16:21, Steven D'Aprano wrote: > > On Tue, Oct 09, 2018 at 10:26:50AM -0700, Guido van Rossum wrote: >> My feeling is that limiting it to strings is fine, but checking those >> strings for resembling identifiers is pointless and wasteful. > > Sure. The question is, do we have

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-09 Thread Steven D'Aprano
On Tue, Oct 09, 2018 at 10:26:50AM -0700, Guido van Rossum wrote: > My feeling is that limiting it to strings is fine, but checking those > strings for resembling identifiers is pointless and wasteful. Sure. The question is, do we have to support uses where people intentionally smuggle

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-09 Thread Steven D'Aprano
On Tue, Oct 09, 2018 at 09:37:48AM -0700, Jeff Hardy wrote: > > When this behavior of set/getattr was discussed a decade or so ago, > > Guido said not to disable it, but I believe he said it should not be > > considered a language feature. There are other situations where CPython > > is 'looser'

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-09 Thread Guido van Rossum
My feeling is that limiting it to strings is fine, but checking those strings for resembling identifiers is pointless and wasteful. On Tue, Oct 9, 2018 at 9:40 AM Jeff Hardy wrote: > On Sun, Oct 7, 2018 at 3:45 PM Terry Reedy wrote: > > > > On 10/7/2018 1:34 PM, Chris Barker via Python-Dev

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-09 Thread Jeff Hardy
On Sun, Oct 7, 2018 at 3:45 PM Terry Reedy wrote: > > On 10/7/2018 1:34 PM, Chris Barker via Python-Dev wrote: > > On Fri, Oct 5, 2018 at 3:01 PM Brett Cannon > > wrote: > > > > I'm also fine with saying that keys in **kwargs that are not proper > > identifiers

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-07 Thread Stephen J. Turnbull
Terry Reedy writes: > When this behavior of set/getattr was discussed a decade or so ago, > Guido said not to disable it, but I believe he said it should not > be considered a language feature. There are other situations where > CPython is 'looser' than the spec. I'm pretty sure that all of

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-07 Thread Terry Reedy
On 10/7/2018 1:34 PM, Chris Barker via Python-Dev wrote: On Fri, Oct 5, 2018 at 3:01 PM Brett Cannon > wrote: I'm also fine with saying that keys in **kwargs that are not proper identifiers is an implementation detail. It's not just **kwargs -- you can also

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-07 Thread Chris Barker via Python-Dev
On Sun, Oct 7, 2018 at 11:42 AM João Santos wrote: > *locals *and *globals* are documented as dictionaries (for example exec's > documentation states that " If only *globals* is provided, it must be a > dictionary") > well, that is specifically about exec() -- it may or may not apply to

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-07 Thread Simon Cross
I would consider it a feature. My reasoning is that the restriction on what can be used as an identifier is a syntax restriction, not a general restriction on what attributes or names can be. ___ Python-Dev mailing list Python-Dev@python.org

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-07 Thread João Santos
*locals *and *globals* are documented as dictionaries (for example exec's documentation states that " If only *globals* is provided, it must be a dictionary") but __dict__ is described as " [a] dictionary or other mapping object". On Sun, 7 Oct 2018 at 19:38, Chris Barker via Python-Dev <

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-07 Thread Chris Barker via Python-Dev
On Fri, Oct 5, 2018 at 3:01 PM Brett Cannon wrote: > I'm also fine with saying that keys in **kwargs that are not proper > identifiers is an implementation detail. > It's not just **kwargs -- you can also use arbitrary names with setattr() / getattr() : In [6]: setattr(foo, "4 not an

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-05 Thread Brett Cannon
I'm also fine with saying that keys in **kwargs that are not proper identifiers is an implementation detail. On Thu, 4 Oct 2018 at 02:20, Serhiy Storchaka wrote: > 04.10.18 11:56, Steven D'Aprano пише: > > While keyword arguments have to be identifiers, using **kwargs allows > > arbitrary

Re: [Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-04 Thread Serhiy Storchaka
04.10.18 11:56, Steven D'Aprano пише: While keyword arguments have to be identifiers, using **kwargs allows arbitrary strings which aren't identifiers: py> def spam(**kwargs): print(kwargs) py> spam(**{"something arbitrary": 1, '\n': 2}) {'something arbitrary': 1, '\n': 2} There

[Python-Dev] Arbitrary non-identifier string keys when using **kwargs

2018-10-04 Thread Steven D'Aprano
While keyword arguments have to be identifiers, using **kwargs allows arbitrary strings which aren't identifiers: py> def spam(**kwargs): ... print(kwargs) ... py> spam(**{"something arbitrary": 1, '\n': 2}) {'something arbitrary': 1, '\n': 2} There is some discussion on Python-Ideas on