[Python-ideas] Re: default as a keyword argument for dict.get and dict.pop

2022-06-08 Thread Barry


> On 8 Jun 2022, at 16:09, Rob Cliffe via Python-ideas 
>  wrote:
> 
> 
> 
>> On 08/06/2022 15:40, Eric V. Smith via Python-ideas wrote:
>> 
>>> On 6/7/2022 4:59 PM, Chris Angelico wrote:
>>> On Wed, 8 Jun 2022 at 00:36,  wrote:
 Hello!
 
 Do you know if there has been discussions around why is the default 
 argument is positional only in the dict methods get and pop?
 
 I think
 
 ```
 d.get(key, default=3)
 ```
 
 way more readable than
 
 ```
 d.get(key, 3)
 ```
 
 specially since max and min builtin functions use default as a keyword 
 argument.
>>> With min and max, it MUST be a keyword argument, because positional
>>> arguments are the values to be compared. So I think the main reason is
>>> "because nobody ever bothered to do it". If there's enough value in
>>> it, that could probably be changed, although mere consistency alone
>>> isn't a very strong argument.
>> 
>> I suspect it's been this way because the API is so old. Now that we have 
>> Argument Clinic it would be easier to implement as a keyword argument. But 
>> there may also be a performance issue with keyword arguments vs. positional. 
>> People are touchy when it comes to dicts!
>> 
>> Eric
> True (and rightly so).  But all that is required is that there is no 
> significant slow-down when the positional argument is used.
> Does that sound feasible?
> People can always choose not to use the keyword form.


Won’t the code have to check for a keyword even if a positional is used and 
therefore it must be slower. Need a benchmark to know by how much.

I’m one of those people that notice uS slow does in access to some APIs.

Barry

> Best wishes
> Rob Cliffe
>> 
>> ___
>> Python-ideas mailing list -- python-ideas@python.org
>> To unsubscribe send an email to python-ideas-le...@python.org
>> https://mail.python.org/mailman3/lists/python-ideas.python.org/
>> Message archived at 
>> https://mail.python.org/archives/list/python-ideas@python.org/message/73OOS3YPUDTZVWFJ5V44X66XZCNXRQV6/
>> Code of Conduct: http://python.org/psf/codeofconduct/
> 
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-ideas@python.org/message/LMVZXUZQAJ4PRKWGTQDP45FS5YDRKRZG/
> Code of Conduct: http://python.org/psf/codeofconduct/

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/SF2TJG6XL37UMZOQCPGZDV5XUDKCKETW/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: default as a keyword argument for dict.get and dict.pop

2022-06-08 Thread Rob Cliffe via Python-ideas



On 08/06/2022 15:40, Eric V. Smith via Python-ideas wrote:


On 6/7/2022 4:59 PM, Chris Angelico wrote:

On Wed, 8 Jun 2022 at 00:36,  wrote:

Hello!

Do you know if there has been discussions around why is the default 
argument is positional only in the dict methods get and pop?


I think

```
d.get(key, default=3)
```

way more readable than

```
d.get(key, 3)
```

specially since max and min builtin functions use default as a 
keyword argument.

With min and max, it MUST be a keyword argument, because positional
arguments are the values to be compared. So I think the main reason is
"because nobody ever bothered to do it". If there's enough value in
it, that could probably be changed, although mere consistency alone
isn't a very strong argument.


I suspect it's been this way because the API is so old. Now that we 
have Argument Clinic it would be easier to implement as a keyword 
argument. But there may also be a performance issue with keyword 
arguments vs. positional. People are touchy when it comes to dicts!


Eric
True (and rightly so).  But all that is required is that there is no 
significant slow-down when the positional argument is used.

Does that sound feasible?
People can always choose not to use the keyword form.
Best wishes
Rob Cliffe


___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/73OOS3YPUDTZVWFJ5V44X66XZCNXRQV6/

Code of Conduct: http://python.org/psf/codeofconduct/


___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/LMVZXUZQAJ4PRKWGTQDP45FS5YDRKRZG/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: default as a keyword argument for dict.get and dict.pop

2022-06-08 Thread Eric V. Smith via Python-ideas



On 6/7/2022 4:59 PM, Chris Angelico wrote:

On Wed, 8 Jun 2022 at 00:36,  wrote:

Hello!

Do you know if there has been discussions around why is the default argument is 
positional only in the dict methods get and pop?

I think

```
d.get(key, default=3)
```

way more readable than

```
d.get(key, 3)
```

specially since max and min builtin functions use default as a keyword argument.

With min and max, it MUST be a keyword argument, because positional
arguments are the values to be compared. So I think the main reason is
"because nobody ever bothered to do it". If there's enough value in
it, that could probably be changed, although mere consistency alone
isn't a very strong argument.


I suspect it's been this way because the API is so old. Now that we have 
Argument Clinic it would be easier to implement as a keyword argument. 
But there may also be a performance issue with keyword arguments vs. 
positional. People are touchy when it comes to dicts!


Eric

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/73OOS3YPUDTZVWFJ5V44X66XZCNXRQV6/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: default as a keyword argument for dict.get and dict.pop

2022-06-08 Thread Rob Cliffe via Python-ideas




On 07/06/2022 15:28, martineznicolas41...@gmail.com wrote:

I think

```
d.get(key, default=3)
```

way more readable than

```
d.get(key, 3)

I completely agree.
Best wishes
Rob Cliffe

___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JXERUZA5J62UPNEQZPUAJCSN53LWMFRE/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: default as a keyword argument for dict.get and dict.pop

2022-06-07 Thread Chris Angelico
On Wed, 8 Jun 2022 at 00:36,  wrote:
>
> Hello!
>
> Do you know if there has been discussions around why is the default argument 
> is positional only in the dict methods get and pop?
>
> I think
>
> ```
> d.get(key, default=3)
> ```
>
> way more readable than
>
> ```
> d.get(key, 3)
> ```
>
> specially since max and min builtin functions use default as a keyword 
> argument.

With min and max, it MUST be a keyword argument, because positional
arguments are the values to be compared. So I think the main reason is
"because nobody ever bothered to do it". If there's enough value in
it, that could probably be changed, although mere consistency alone
isn't a very strong argument.

ChrisA
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/26RTH4UI7B26DMWP6LSIK4VIAV7NCIQT/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: default as a keyword argument for dict.get and dict.pop

2022-06-07 Thread Steven D'Aprano
On Tue, Jun 07, 2022 at 02:28:51PM -, martineznicolas41...@gmail.com wrote:

> Do you know if there has been discussions around why is the default 
> argument is positional only in the dict methods get and pop?

Its probably just left over from earlier versions of Python when builtin 
functions only used positional arguments.

Positional arguments are a little faster than keyword arguments, and 
especially for builtin functions, easier to program.

You could try making an enhancement request on the bug tracker and see 
if any one is willing to do the work.

-- 
Steve
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/XX5IGYNZHBGVBWTKDAYRV7IH7P44TLDB/
Code of Conduct: http://python.org/psf/codeofconduct/