Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103087
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Terry Reedy <tjreedy@udel.edu> |
| Newsgroups | comp.lang.python |
| Subject | Re: Python keyword args can be any string |
| Date | Thu, 18 Feb 2016 01:31:12 -0500 |
| Lines | 46 |
| Message-ID | <mailman.233.1455777087.22075.python-list@python.org> (permalink) |
| References | <56c559c2$0$2916$c3e8da3$76491128@news.astraweb.com> <857fi236ek.fsf@benfinney.id.au> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | news.uni-berlin.de SZi/XdxhtrdsGgs4766NeQCPcYfk4aV34m+GrCBcWvLw== |
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'guido': 0.05; 'caller': 0.07; 'bindings': 0.09; 'incidental': 0.09; 'kwargs': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:string': 0.09; 'unpacking': 0.09; 'bug': 0.10; 'jan': 0.11; 'def': 0.13; "'':": 0.16; '12:59': 0.16; '23,': 0.16; '42,': 0.16; 'cares': 0.16; 'example)': 0.16; 'feature?': 0.16; 'identifiers': 0.16; 'imo.': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'string:': 0.16; 'unpacked': 0.16; "{'':": 0.16; 'wrote:': 0.16; 'string': 0.17; 'arguments': 0.22; 'keys': 0.22; 'trying': 0.22; 'am,': 0.23; 'leave': 0.23; 'errors': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'function': 0.28; 'dictionary': 0.29; 'feature,': 0.29; 'key,': 0.29; 'says': 0.32; 'problem': 0.33; "d'aprano": 0.33; 'raised': 0.33; 'steven': 0.33; 'similar': 0.33; 'i.e.': 0.35; 'cases': 0.36; 'keyword': 0.36; 'received:71': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'seem': 0.37; 'does': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'some': 0.40; 'your': 0.60; 'ago.': 0.61; 'skip:n 10': 0.62; 'is.': 0.63; 'times': 0.63; 'today': 0.65; 'rare': 0.66; '\xe2\x80\x93': 0.72; 'dict,': 0.84; 'subject:any': 0.84; 'received:fios.verizon.net': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | pool-71-185-227-36.phlapa.fios.verizon.net |
| User-Agent | Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 |
| In-Reply-To | <857fi236ek.fsf@benfinney.id.au> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21rc2 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:103087 |
Show key headers only | View raw
On 2/18/2016 12:59 AM, Ben Finney wrote:
> Steven D'Aprano <steve+comp.lang.python@pearwood.info> writes:
>
>> Today I learned that **kwargs style keyword arguments can be any string:
>>
>>
>> py> def test(**kw):
>> ... print(kw)
>> ...
>> py> kwargs = {'abc-def': 42, '': 23, '---': 999, '123': 17}
>> py> test(**kwargs)
>> {'': 23, '123': 17, '---': 999, 'abc-def': 42}
>>
>>
>> Bug or feature?
>
> Incidental feature, I think.
The was discussed on pydev some years ago. Guido says leave as is. This
and similar cases of allowing non-identifier is string-dicts does not
seem to cause a problem and apparently has a few rare legitimate usages.
> If the caller is deliberately unpacking a dict, it's on them to ensure
> the keys are valid identifiers or wear the consequences.
>
> If the function cares so little about the keys in its kwargs that (as in
> your example) any string will do for each key, then it's a consenting
> actor IMO.
>
> The times when it's a problem – i.e. that the function is trying to use
> items from that dictionary as name bindings – the errors will be raised
> to the caller that unpacked that mapping. That's where the errors belong.
>
--
Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python keyword args can be any string Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-02-18 16:42 +1100
Re: Python keyword args can be any string Chris Angelico <rosuav@gmail.com> - 2016-02-18 16:57 +1100
Re: Python keyword args can be any string Ben Finney <ben+python@benfinney.id.au> - 2016-02-18 16:59 +1100
Re: Python keyword args can be any string Terry Reedy <tjreedy@udel.edu> - 2016-02-18 01:31 -0500
Re: Python keyword args can be any string Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-02-18 07:55 +0000
Re: Python keyword args can be any string Steven D'Aprano <steve@pearwood.info> - 2016-02-19 11:03 +1100
Re: Python keyword args can be any string Ben Finney <ben+python@benfinney.id.au> - 2016-02-19 11:58 +1100
Re: Python keyword args can be any string Rustom Mody <rustompmody@gmail.com> - 2016-02-19 03:41 -0800
csiph-web