Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I *____knew* I had some reason for not logging you off... If I could just remember what it was.


devel / comp.lang.python / RE: Changing calling sequence

SubjectAuthor
* Changing calling sequenceMichael F. Stemper
+* Re: Changing calling sequenceStefan Ram
|`- Re: Changing calling sequenceStefan Ram
+* Re: Changing calling sequenceTobiah
|+* RE: Changing calling sequenceDavid Raymond
||`* Re: Changing calling sequenceStefan Ram
|| `- RE: Changing calling sequenceDavid Raymond
|`- Re: Changing calling sequenceMartin Di Paola
+- Re: Changing calling sequence2QdxY4RzWzUUiLuE
+* Re: Changing calling sequenceanthony.flury
|`- Re: Changing calling sequenceMichael F. Stemper
+- Re: Changing calling sequencedn
+- Re: Changing calling sequence2QdxY4RzWzUUiLuE
+- Re: Changing calling sequencedn
+- Re: Changing calling sequenceChris Angelico
`* Re: Changing calling sequence2QdxY4RzWzUUiLuE
 `- Re: Changing calling sequenceGreg Ewing

1
Changing calling sequence

<t5gdv7$6et$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18222&group=comp.lang.python#18222

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: michael....@gmail.com (Michael F. Stemper)
Newsgroups: comp.lang.python
Subject: Changing calling sequence
Date: Wed, 11 May 2022 08:33:27 -0500
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <t5gdv7$6et$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 May 2022 13:33:27 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="8dfbd2b7ee543336ef68dbc21bdf31b2";
logging-data="6621"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4pg6dIw/UMkwt07LT9hO4ossrYi2k7T0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:mVNMyQ5Y/xsAFfN20DyPqtV5SB8=
Content-Language: en-US
X-Mozilla-News-Host: news://news.eternal-september.org:119
 by: Michael F. Stemper - Wed, 11 May 2022 13:33 UTC

I have a function that I use to retrieve daily data from a
home-brew database. Its calling sequence is;

def TempsOneDay( year, month, date ):

After using it (and its friends) for a few years, I've come to
realize that there are times where it would be advantageous to
invoke it with a datetime.date as its single argument.

As far as I can tell, there are three ways for me to proceed:
1. Write a similar function that takes a single datetime.date
as its argument.
2. Rewrite the existing function so that it takes a single
argument, which can be either a tuple of (year,month,date)
or a datetime.date argument.
3. Rewrite the existing function so that its first argument
can be either an int (for year) or a datetime.date. The
existing month and date arguments would be optional, with
default=None. But, if the first argument is an int, and
either of month or date is None, an error would be raised.

The first would be the simplest. However, it is obviously WET
rather than DRY.

The second isn't too bad, but a change like this would require that
I find all places that the function is currently used and insert a
pair of parentheses. Touching this much code is risky, as well
as being a bunch of work. (Admittedly, I'd only do it once.)

The third is really klunky, but wouldn't need to touch anything
besides this function.

What are others' thoughts? Which of the approaches above looks
least undesirable (and why)? Can anybody see a fourth approach?

--
Michael F. Stemper
This post contains greater than 95% post-consumer bytes by weight.

Re: Changing calling sequence

<overloading-20220511145916@ram.dialup.fu-berlin.de>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18223&group=comp.lang.python#18223

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: 11 May 2022 14:01:11 GMT
Organization: Stefan Ram
Lines: 29
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <overloading-20220511145916@ram.dialup.fu-berlin.de>
References: <t5gdv7$6et$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 3xv6RM+5tI5y8jX/vDZD1wYKPQ/sz5nHJJhQlLcr2jX7Ag
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Wed, 11 May 2022 14:01 UTC

"Michael F. Stemper" <michael.stemper@gmail.com> writes:
>I have a function that I use to retrieve daily data from a
>home-brew database. Its calling sequence is;
>def TempsOneDay( year, month, date ):

I never heard something like "def ... :" called a "calling
sequence". "year, month, date" is a "parameter list".

>1. Write a similar function that takes a single datetime.date
> as its argument.
....
>The first would be the simplest. However, it is obviously WET
>rather than DRY.

This would be quite pythonic. For example, "datetime.date"
has .fromtimestamp(timestamp), .fromordinal(ordinal),
.fromisoformat(date_string), ...

>What are others' thoughts? Which of the approaches above looks
>least undesirable (and why)? Can anybody see a fourth approach?

The fourth approach would be to allow only a single
datetime.date argument, and then write

TempsOneDay( datetime.date( year, month, day ))

if need be.

Re: Changing calling sequence

<t5gl5r$j27$1@gioia.aioe.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18224&group=comp.lang.python#18224

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!i2H2dPTP1PDAFtyjvKGI8g.user.46.165.242.75.POSTED!not-for-mail
From: tob...@tobiah.org (Tobiah)
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: Wed, 11 May 2022 08:36:26 -0700
Organization: Aioe.org NNTP Server
Message-ID: <t5gl5r$j27$1@gioia.aioe.org>
References: <t5gdv7$6et$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="19527"; posting-host="i2H2dPTP1PDAFtyjvKGI8g.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Tobiah - Wed, 11 May 2022 15:36 UTC

On 5/11/22 06:33, Michael F. Stemper wrote:
> I have a function that I use to retrieve daily data from a
> home-brew database. Its calling sequence is;
>
> def TempsOneDay( year, month, date ):
>
> After using it (and its friends) for a few years, I've come to
> realize that there are times where it would be advantageous to
> invoke it with a datetime.date as its single argument.

You could just use all keyword args:

def TempsOneDay(**kwargs):

if 'date' in kwargs:
handle_datetime(kwargs['date'])
elif 'year' in kwargs and 'month' in kwargs and 'day' in kwargs:
handle_args(kwargs['year'], kwargs['month'], kwargs['day'])
else:
raise Exception("Bad keyword args")

TempsOneDay(date=datetime.datetime.now)

TempsOneDay(year=2022, month=11, day=30)

Re: Changing calling sequence

<constructors-20220511165445@ram.dialup.fu-berlin.de>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18225&group=comp.lang.python#18225

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: 11 May 2022 15:55:06 GMT
Organization: Stefan Ram
Lines: 29
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <constructors-20220511165445@ram.dialup.fu-berlin.de>
References: <t5gdv7$6et$1@dont-email.me> <overloading-20220511145916@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de FactAUPt0s8lvUhc5l+GJQf0y77ftfcaV2tUJtAEvGqR7X
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Wed, 11 May 2022 15:55 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:
>This would be quite pythonic. For example, "datetime.date"
>has .fromtimestamp(timestamp), .fromordinal(ordinal),
>.fromisoformat(date_string), ...

In his talk "Python's Class Development Toolkit", in 2013,
Raymond Hettinger elaborated on classes with more than one
constructor:

|Whenever you have a constructor where /everyone/ should get
|their wish, you /should/ have more that one constructor.
| |There is a constructor war; people digging in their positions
|for a reason: they /need/ that constructor! They shall not be
|denied.
| |So, is this common or normal? Sure! We do it in Python itself!
| |The one true way to make a datetime of course is, uh, "year,
|month, and day".
| |But perhaps you work with timestamps at which point that
|constructor is really awkward; so we give you a second
|constructor, uh, "fromtimestamp", that will convert this time
|stamp into a date.
| Raymond Hettinger in 2013.

Re: Changing calling sequence

<mailman.371.1652291248.20749.python-list@python.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18226&group=comp.lang.python#18226

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: 2QdxY4Rz...@potatochowder.com
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: Wed, 11 May 2022 12:47:18 -0500
Lines: 34
Message-ID: <mailman.371.1652291248.20749.python-list@python.org>
References: <t5gdv7$6et$1@dont-email.me>
<Ynv2ptnuVBgUaUHA@scrozzle>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.uni-berlin.de WeyDuWWrF4TPA5Nh6zfSeg76+O9FCd7jvND8O67Oq+oA==
Return-Path: <2QdxY4RzWzUUiLuE@potatochowder.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'def':
0.04; '(for': 0.05; 'int': 0.09; 'obviously': 0.09; 'received:78':
0.09; 'arguments': 0.16; 'database.': 0.16;
'from:addr:2qdxy4rzwzuuilue': 0.16; 'from:addr:potatochowder.com':
0.16; 'invoke': 0.16; 'message-id:@scrozzle': 0.16;
'received:136.243': 0.16; 'received:78.46': 0.16; 'received:www458
.your-server.de': 0.16; 'received:your-server.de': 0.16;
'rewrite': 0.16; 'tests,': 0.16; 'tuple': 0.16; 'year)': 0.16;
'wrote:': 0.16; 'to:addr:python-list': 0.20; "i've": 0.22; 'code':
0.23; 'received:de': 0.23; '(and': 0.25; 'function': 0.27;
'error': 0.29; 'takes': 0.31; 'think': 0.32; 'extract': 0.32;
'realize': 0.32; 'received:136': 0.32; 'retrieve': 0.32; 'there':
0.33; 'year,': 0.33; 'header:In-Reply-To:1': 0.34; 'using': 0.37;
"it's": 0.37; 'least': 0.39; 'single': 0.39; 'use': 0.39;
'should': 0.40; 'come': 0.62; 'clear': 0.64; 'daily': 0.65;
'similar': 0.65; 'readers': 0.69; 'sequence': 0.69; 'times': 0.69
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <t5gdv7$6et$1@dont-email.me>
X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com
X-Virus-Scanned: Clear (ClamAV 0.103.5/26538/Wed May 11 10:06:03 2022)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <Ynv2ptnuVBgUaUHA@scrozzle>
X-Mailman-Original-References: <t5gdv7$6et$1@dont-email.me>
 by: 2QdxY4Rz...@potatochowder.com - Wed, 11 May 2022 17:47 UTC

On 2022-05-11 at 08:33:27 -0500,
"Michael F. Stemper" <michael.stemper@gmail.com> wrote:

> I have a function that I use to retrieve daily data from a
> home-brew database. Its calling sequence is;
>
> def TempsOneDay( year, month, date ):
>
> After using it (and its friends) for a few years, I've come to
> realize that there are times where it would be advantageous to
> invoke it with a datetime.date as its single argument.
>
> As far as I can tell, there are three ways for me to proceed:
> 1. Write a similar function that takes a single datetime.date
> as its argument.
> 2. Rewrite the existing function so that it takes a single
> argument, which can be either a tuple of (year,month,date)
> or a datetime.date argument.
> 3. Rewrite the existing function so that its first argument
> can be either an int (for year) or a datetime.date. The
> existing month and date arguments would be optional, with
> default=None. But, if the first argument is an int, and
> either of month or date is None, an error would be raised.
>
> The first would be the simplest. However, it is obviously WET
> rather than DRY.

It's also the least disruptive to existing code and tests, and the most
clear to readers (whether or not they're familiar with said existing
code).

What pieces, exactly, do you think you would repeat, especially after
you extract the common logic into a new function that should be simpler
than either API-level function.

RE: Changing calling sequence

<mailman.372.1652295680.20749.python-list@python.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18227&group=comp.lang.python#18227

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: David.Ra...@tomtom.com (David Raymond)
Newsgroups: comp.lang.python
Subject: RE: Changing calling sequence
Date: Wed, 11 May 2022 19:01:16 +0000
Lines: 25
Message-ID: <mailman.372.1652295680.20749.python-list@python.org>
References: <t5gdv7$6et$1@dont-email.me> <t5gl5r$j27$1@gioia.aioe.org>
<HE1PR0701MB2857BFBEFAF93C3C3ECB2F0687C89@HE1PR0701MB2857.eurprd07.prod.outlook.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
X-Trace: news.uni-berlin.de OPxx2Wnyt/TuIrQjJzKnHQszb2Tvlr950SL3JJR+T/Rg==
Return-Path: <David.Raymond@tomtom.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="1024-bit key; unprotected key"
header.d=tomtom.com header.i=@tomtom.com header.b=MNgcYdiq;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.046
X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'def': 0.04; 'elif': 0.09;
'else:': 0.09; 'args:': 0.16; 'database.': 0.16; 'invoke': 0.16;
'skip:> 20': 0.16; 'calls': 0.19; 'to:addr:python-list': 0.20;
"i've": 0.22; 'maybe': 0.22; 'to:name:python-list@python.org':
0.24; '(and': 0.25; 'past': 0.25; 'function': 0.27; 'raise': 0.31;
'keyword': 0.32; 'realize': 0.32; 'retrieve': 0.32; "wouldn't":
0.32; 'but': 0.32; 'there': 0.33; 'year,': 0.33; 'header:In-Reply-
To:1': 0.34; 'main': 0.37; 'using': 0.37; 'could': 0.38; 'single':
0.39; 'this,': 0.39; 'use': 0.39; 'define': 0.40; 'skip:i 20':
0.62; 'come': 0.62; 'skip:k 10': 0.64; 'daily': 0.65; 'skip:t 20':
0.66; 'body': 0.67; 'sequence': 0.69; 'times': 0.69
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=jkqHTX3/L1VbwQoe2uDaa0TVC3FispeTJqem7+VhzuuYyNSq+PEgWGXX0pCKgdGEogSMVvBb9ctIkPXn7zWjnmfiQKjCp5uqY1oQW+J9q62ifRLRZgdp4fniDPk0eKDhQePGEFO5dC3/dF0M/pSv6hikx9OX8s4aBtGF7YVK+ettKj98jAlGq9e2hCDm1HQ2TTq0/yaJeGaY7pWVQDgOyjrMqtWZlX9lIkRacOWa3N3S46raghqEn+Oph4Zp82WfM2aE9dzwlwY3F9l//m8FdRPg4Fv3Ljj4rVz2R05K1xNZ76BFKtHB1kyXUmaU43CqaBgLnlAarPgc1ujJLjZeWg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
bh=zJ7oj6uc8wyzBe82836djR9lRsp4Mc+U8o2Zno9qDWE=;
b=kbZBjchCvwxeGsSHeOpAS2L3U/QfYf6J8f6xE0p4UXpX/4cFotX7qV4Ax5R2A7xjaBWf/k8Mg9r6R0qHSUJqcLt3nl4wblgJwJiKgUKAm97wi4sm6BBLeyafBBn+j4svuXyrkB3QWwaysqSsAL16i9Q35QyONXPgBOz5qIh+PvN6PAvcpmmQrUr1t8VnhWW5BhHX0Ts0miK8njerBzA7whf4e+Pwip4cvv93BTSEUWU825OQWcS91AEyCWiW2umcLJyMOUQH6UeuAlW71fCsZ9o6VesHiG8ntUNq+lA7u9P+VlSn6UeLiX62bP0UhxHiUwFxKdcIgRyY/ygtwCqAEQ==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=tomtom.com; dmarc=pass action=none header.from=tomtom.com;
dkim=pass header.d=tomtom.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tomtom.com;
s=selector2;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=zJ7oj6uc8wyzBe82836djR9lRsp4Mc+U8o2Zno9qDWE=;
b=MNgcYdiq/+SRh9ZkgRRXpPhMor06JpV6IH2hfrHGEb36yfXNT6ZoMB0ukd/ZXTlrwsWZe+8c/W/P1eivPuwcojoRDhR5n6z2PFCawUo9CAjY96RNEmESEHWiLw548SL0eEp7nQlLUyaxvka0hwwyos3VkIckzdFXVpbKQKFR9jA=
Thread-Topic: Changing calling sequence
Thread-Index: AQHYZVeOCNqinGstRkSp33CTc3J01K0Z5l0lgAAetlA=
In-Reply-To: <t5gl5r$j27$1@gioia.aioe.org>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
authentication-results: dkim=none (message not signed)
header.d=none;dmarc=none action=none header.from=tomtom.com;
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: 51ef64d6-228f-4077-5856-08da3380a026
x-ms-traffictypediagnostic: AM0PR0702MB3810:EE_
x-microsoft-antispam-prvs: <AM0PR0702MB38100084FE763F718597003687C89@AM0PR0702MB3810.eurprd07.prod.outlook.com>
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: rk9U6Bu6JvHNAObDWVKPpcFWwWpWvDagF69gkrCGk0hNDMiBpAumoSVAzDNqLZHbAIvncE9IwVY3BGF6BDWzbekth+6YGYsNo/3XZQLReQZkUtDvMJY27cxhiLhrxNZwbF3vwiE1kExbyMw/DoknJpqQs293O5qATujmLF2Fwi0RWFWFVt7/HoxMbHl1HP6rXOv+A4cZEcUBZrCiGeg9lKl3VIMw7rDeoWA98QLVkmo0ovwTsbqujMkzQNgmdChIKrSJOp7oXaV1KDIorxPDj6I5CVHvPcH3cfcvrYrbKJoUSH5hpqaVwTYahK04zunne96Q2TVawgou7AS4xav1aAn6Rc1nSeZM0XFNWETRd8PGqQLA5RQWpvXhA6fhKRs8xtFGg9IyRYRvOPdwGgKjQOI9omsU0YLc4axm/dLdp1+qndk4AFlJCJj+QTZPGuoxtJnofsgeVGc9gg75DhWC40XRA5kEoqBYEzNlaiODkZHRnHvXC0uxEvpLHDsNdc1yVKOkqcWCbrgRBTb/WTMOk/lliipxvhjOh6abvNsMp1u9p8jyrkA2TRXMrgCPcMDZLgpogMNmuoz9H9uZHvUsv6T/5bqdXfK/y2lgrvDt8m2oXcb3pxjCuaj3cflgSJ4eCThWaldZ7izsB5h0NcNqaYFbP0O+m6F8NPHTaab+UlM/BgGgjY7sNQGJU/V6i0n1BKKw3k0pcPXQ7WgYuH1yl4VfCLez2o6/ZP+awNTxvOh3wCQ9whOOqSk7ln+RHs//
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:HE1PR0701MB2857.eurprd07.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230001)(4636009)(366004)(55016003)(3480700007)(2906002)(52536014)(5660300002)(33656002)(66476007)(64756008)(66446008)(7116003)(8676002)(66946007)(66556008)(76116006)(8936002)(83380400001)(6916009)(186003)(86362001)(38070700005)(9686003)(38100700002)(6506007)(7696005)(26005)(122000001)(316002)(71200400001)(508600001);
DIR:OUT; SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: OH/uoC01FZrdEagt3wJiPnWYeJH7GH27XAMyUNByBvMCM
rWxYOwDIfoyKKMZjNr5GRZzVj5+IKLf5G7BBFCyBKMHph
KFjfjbM0D2r/r88dHqJgV1ngNcNoO3TpEH/XLxFBiQtu9
AKY6A+wIu6dPv3lFCHyQq3KS5MMR5ynRsWRDHULLVRldN
E96H6SHRy3xj25MzNcziafk7J0xu7d9BEYQaOquIcTxyp
6E1e/3DwCKLu5xk9T9ZU8KnNKddkdadXOXz0LOj90L77/
4biLcFYIGFcnxQHFNwviPNKnCZ4MDi8ngH14vc3RPemHq
kmfQI+jlEuutnBVYXVScuwKGSP/oJYqKvlIHDsPRbqTLi
meGhOBpSFZK/dUovQ/Djwh+hSoSqCTQHZK/l6xH8VUp+q
80C6e20OlsRshdmpJEbd1CZofzjNp20bhJGgYlXW/ThQy
9YObXRoLwBIqbo3Iud8ehSaxGcVbQkIoeyva2+rHJxJoV
oci/5uoAJpw7WUitFSq1nG3sI8VwHqz1EpSr0arlm8cjG
omX6mgnqcjIIG0ybya5dhcIdSpMbTZaPadK/18/D01NaM
r+pwRhTwZZHl0JbL4NGz1lhYhJSpYNo5+Qwd7Tia9o6OH
5qnbgKbnfVcZyYV1kv2L1NDn0G5+Ts4kcMXKVKmxH0UjP
r3Oaq2STrLVJD9OglOShMH83pKA5OBtlAanrmbN6BpptW
o3GTOvlWJNrnXAXHeRBiR42YGcH5USb96o8Kh9qeExMIF
mEdWW5bf6leIOLvvOKaKwoWDigOHx6dtJ/uwstT+uRl+z
9xJmC+77JO6iCDkL00Rn2JeLo8jaEXpJhVnNB4ZPsRaEp
anUoUuzwjpciNgJRZSKilKX9t/eEdV10oV573p7rP2iBZ
OjeAXRstd36qtp2DQNJA+zhBv03NqIv4DYRr4dMieYUD9
9b19IA4x29+XP3b42QrbWMzssAsGtlk4ooF8VQzbmwLyN
U2lDe4u8oJ7kyJSqgcm6J1J1WNGe3pu4oEoQSfHLyqxav
H6aD48UALc64Xv6814V32mAluayD/xU3+OTEN/BNprF2h
ms3+viywyE0WGXv2lVmLTYEhC2wSEI8PoIYCyI+l6SkFP
ZWbOEffqQ/iGxOygJA8A9PlDCrQhaTugibRhyWdBIO8uQ
K16iSd41xz7MfOCuwsLRVhUI9lww3ngdHcX/gBXUlWzA+
ODIIff4BlPP/t3u3Ql4aB6y95410ieUc9m1RW1piC+07i
5gxSNAskd0pPgWpELBzWAtZ5iV6Vdk8VUDcPJU67FMvQU
8ERZqinK4ikqbyYV34uEpRJgYxRlb15iT9EYsf75v/KNd
+P4c/dWfCbtAz0hNzIPScYenU/7+0xYQZV5cIyGrTaYAk
c7f+mYGpUBSZGghHjATKd/Tf4bji0MaJsXqnMk2/GfIRS
jzoLkv9EMv1L2M3sia6vrglVSb2KZK/XP6tk98uXeN8rL
rpi4ZzJOTL9azgBr1H7F0QHgGtxiJjmnunFyiYZ9p+JCn
fVNIQzZa95/jFuV8jKv0ENX/X9JqrneZApAD+lb+fW42K
Da5z6dZjtFtE4vo/4OfMH2T4f8vAFIb3O2+hBQlpwOaYX
OYLrUvN0LdwvE+7UPQZLFVqE/QXtoi3659Uv4x2XV3YgH
aVgAfcVtaJb0DREW089pZMPehTrKr1ENj3mP3JJ9kSsXA
g/DRRHdb5yxQO4eKpVfollrYtP/fj9PYBBIPKa1OsW7fW
6Je4un6cw2HTf5Mk=
X-OriginatorOrg: tomtom.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: HE1PR0701MB2857.eurprd07.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 51ef64d6-228f-4077-5856-08da3380a026
X-MS-Exchange-CrossTenant-originalarrivaltime: 11 May 2022 19:01:16.1575 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 374f8026-7b54-4a3a-b87d-328fa26ec10d
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: kgH0Jbk613Cj3CpE7oILztC0ii64eS0iNOtuuxBVV2g2xeyxzemA3gsQ6nB2xgUUQEc7f8T+cZkKUVpNkZahXvZRsDr7sQEX10VBbcnF4vk=
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0702MB3810
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <HE1PR0701MB2857BFBEFAF93C3C3ECB2F0687C89@HE1PR0701MB2857.eurprd07.prod.outlook.com>
X-Mailman-Original-References: <t5gdv7$6et$1@dont-email.me>
<t5gl5r$j27$1@gioia.aioe.org>
 by: David Raymond - Wed, 11 May 2022 19:01 UTC

>> I have a function that I use to retrieve daily data from a
>> home-brew database. Its calling sequence is;
>>
>> def TempsOneDay( year, month, date ):
>>
>> After using it (and its friends) for a few years, I've come to
>> realize that there are times where it would be advantageous to
>> invoke it with a datetime.date as its single argument.
>
>You could just use all keyword args:
>
>def TempsOneDay(**kwargs):
>
> if 'date' in kwargs:
> handle_datetime(kwargs['date'])
> elif 'year' in kwargs and 'month' in kwargs and 'day' in kwargs:
> handle_args(kwargs['year'], kwargs['month'], kwargs['day'])
> else:
> raise Exception("Bad keyword args")
>
>TempsOneDay(date=datetime.datetime.now)
>
>TempsOneDay(year=2022, month=11, day=30)
>
Maybe not the prettiest, but you could also define it like this, which also wouldn't require changing of any existing calls or the main body of the function past this if block.
def TempsOneDay(*dateComponents):
if len(dateComponents) == 3:
year, month, date = dateComponents
elif len(dateComponents) == 1 and isinstance(dateComponents[0], datetime.date):
year, month, date = (dateComponents[0].year, dateComponents[0].month, dateComponents[0].day)
else:
raise Exception("Error message here")

Re: Changing calling sequence

<help-20220511200646@ram.dialup.fu-berlin.de>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18228&group=comp.lang.python#18228

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: 11 May 2022 19:07:54 GMT
Organization: Stefan Ram
Lines: 15
Expires: 1 Apr 2023 11:59:58 GMT
Message-ID: <help-20220511200646@ram.dialup.fu-berlin.de>
References: <t5gdv7$6et$1@dont-email.me> <t5gl5r$j27$1@gioia.aioe.org> <mailman.372.1652295680.20749.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de m/iIFRme4tTaB/R6W/TMewRmYOTOSW+tTP7JNtWUJMg7h7
X-Copyright: (C) Copyright 2022 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Wed, 11 May 2022 19:07 UTC

David Raymond <David.Raymond@tomtom.com> writes:
>def TempsOneDay(*dateComponents):
> if len(dateComponents) == 3:
> year, month, date = dateComponents
> elif len(dateComponents) == 1 and isinstance(dateComponents[0], datetime.date):
> year, month, date = (dateComponents[0].year, dateComponents[0].month, dateComponents[0].day)
> else:
> raise Exception("Error message here")

|>>> help( TempsOneDay )
|Help on function TempsOneDay in module __main__:
| |TempsOneDay(*dateComponents)

Re: Changing calling sequence

<mailman.374.1652299109.20749.python-list@python.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18230&group=comp.lang.python#18230

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: anthony....@btinternet.com (anthony.flury)
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: Wed, 11 May 2022 20:58:21 +0100 (BST)
Lines: 55
Message-ID: <mailman.374.1652299109.20749.python-list@python.org>
References: <t5gdv7$6et$1@dont-email.me>
<45cd23fe.acec.180b4b37653.Webtop.104@btinternet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 23k3AVaPZRvpihgl0gW3rAvu+1wRQed1fTlsVLdz1Tow==
Return-Path: <anthony.flury@btinternet.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=btinternet.com header.i=@btinternet.com header.b=iC4BkNbX;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.020
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'looks': 0.02; 'argument':
0.04; 'def': 0.04; '(for': 0.05; 'bunch': 0.05; 'approach?': 0.09;
'approaches': 0.09; 'int': 0.09; 'obviously': 0.09; 'url:mailman':
0.15; 'arguments': 0.16; 'database.': 0.16; 'fourth': 0.16;
'invoke': 0.16; 'rewrite': 0.16; 'tuple': 0.16; 'year)': 0.16;
'to:addr:python-list': 0.20; "i've": 0.22; 'code': 0.23; "i'd":
0.24; '(and': 0.25; 'anything': 0.25; 'url-ip:188.166.95.178/32':
0.25; 'url-ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'url-
ip:188.166/16': 0.25; 'interface': 0.26; 'wednesday,': 0.26;
"isn't": 0.27; 'function': 0.27; 'error': 0.29; 'header:User-
Agent:1': 0.30; 'takes': 0.31; 'url-ip:188/8': 0.31; 'anybody':
0.32; 'realize': 0.32; 'retrieve': 0.32; "wouldn't": 0.32; 'but':
0.32; 'there': 0.33; 'year,': 0.33; 'same': 0.34; 'work.': 0.34;
'header:In-Reply-To:1': 0.34; 'change': 0.36; 'currently': 0.37;
'really': 0.37; 'using': 0.37; 'least': 0.39; 'single': 0.39;
'use': 0.39; 'received:213': 0.40; 'michael': 0.60; 'above': 0.62;
'from:': 0.62; 'to:': 0.62; 'come': 0.62; 'daily': 0.65;
'similar': 0.65; 'touch': 0.65; 'well': 0.65; 'skip:t 20': 0.66;
'skip:t 30': 0.67; 'sequence': 0.69; 'times': 0.69; 'url:dtd':
0.74; 'url:xhtml': 0.74; 'url:1999': 0.75; '------': 0.76;
'sent:': 0.78; 'url:xhtml1': 0.83; 'anthony': 0.84; 'touching':
0.84; 'greater': 0.91; 'url:xhtml1-strict': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com;
s=btmx201904; t=1652299101;
bh=ruNuMPCFETeHs61LlnI2gVD5tAMA50g3PmH7gaEuaRM=;
h=To:Message-ID:In-Reply-To:References:Subject:MIME-Version:From:Date;
b=iC4BkNbXqhV5nHJJ4s9BukW9D+j1RpuDPL43h8rzr8RMtRoBwgyz9Ls5yV/e5Wz7ywOlwCZXsClx8k1awf0WhIe1SWGb0FI0aJLwASSbkYZX2wVOx+AJwLH1TZuvdtSUCibEE2FL9qUa1nmgerzcMencbsWRhx4iXuZYILk1mw0g/13vmAvjq4As1MjF+C3WDi4zkjhyTln9xWaykjZpHDf4T6lnwiXhKnUKrVrP0mfGOcKr0QUIZT6mgwYfq/k6Uy3c5TiJpZbg8zDUaROENkzXNw1+H4dsSc28ydHrpuxB6DNy2FQmGvHQ75HILYsKxFFCEpCJpDoi31sNApn8HQ==
Authentication-Results: btinternet.com; none
X-SNCR-Rigid: 613A912422D72AF9
X-OWM-Env-Sender: anthony.flury@btinternet.com
X-VadeSecure-score: verdict=clean score=0/300, class=clean
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvfedrgeehgddugedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefvkfgjfhfugggtfghihfffsegrtdersgdtreejnecuhfhrohhmpedfrghnthhhohhnhidrfhhluhhrhidfuceorghnthhhohhnhidrfhhluhhrhiessghtihhnthgvrhhnvghtrdgtohhmqeenucggtffrrghtthgvrhhnpeffgeeiueekfeetveeuhfetveefudfgiefgffevteduveevhfevgfehfeeugeevueenucffohhmrghinhepphihthhhohhnrdhorhhgnecukfhppedutddrvddrheegrddutdegpdekuddrudehgedrfeegrdduvdegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheprhgvqdhprhguqdhugihfvghpqddtvdefrdgsthhmgidqphhrugdrshihnhgthhhrohhnohhsshdrnhgvthdpihhnvghtpedutddrvddrheegrddutdegpdhmrghilhhfrhhomheprghnthhhohhnhidrfhhluhhrhiessghtihhnthgvrhhnvghtrdgtohhmpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepmhhitghhrggvlhdrshhtvghmphgvrhesghhmrghilhdrtghomhdprhgtphhtthhopehphihthhhonhdqlhhishhtsehphihthhhonhdrohhrgh
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-SNCR-hdrdom: btinternet.com
In-Reply-To: <t5gdv7$6et$1@dont-email.me>
User-Agent: OWM Mail 3
X-SID: 104
X-Originating-IP: [81.154.34.124]
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <45cd23fe.acec.180b4b37653.Webtop.104@btinternet.com>
X-Mailman-Original-References: <t5gdv7$6et$1@dont-email.me>
 by: anthony.flury - Wed, 11 May 2022 19:58 UTC

Why not do :

def TempsOneDayDT(date:datetime.date):
return TempsOneDay(date.year, date.month, date.day)

No repeat of code - just a different interface to the same
functionality.

------ Original Message ------
From: "Michael F. Stemper" <michael.stemper@gmail.com>
To: python-list@python.org
Sent: Wednesday, 11 May, 22 At 14:33
Subject: Changing calling sequence
I have a function that I use to retrieve daily data from a
home-brew database. Its calling sequence is;
def TempsOneDay( year, month, date ):
After using it (and its friends) for a few years, I've come to
realize that there are times where it would be advantageous to
invoke it with a datetime.date as its single argument.
As far as I can tell, there are three ways for me to proceed:
1. Write a similar function that takes a single datetime.date
as its argument.
2. Rewrite the existing function so that it takes a single
argument, which can be either a tuple of (year,month,date)
or a datetime.date argument.
3. Rewrite the existing function so that its first argument
can be either an int (for year) or a datetime.date. The
existing month and date arguments would be optional, with
default=None. But, if the first argument is an int, and
either of month or date is None, an error would be raised.

The first would be the simplest. However, it is obviously WET
rather than DRY.
The second isn't too bad, but a change like this would require that
I find all places that the function is currently used and insert a
pair of parentheses. Touching this much code is risky, as well
as being a bunch of work. (Admittedly, I'd only do it once.)
The third is really klunky, but wouldn't need to touch anything
besides this function.
What are others' thoughts? Which of the approaches above looks
least undesirable (and why)? Can anybody see a fourth approach?
--
Michael F. Stemper
This post contains greater than 95% post-consumer bytes by weight.
--
https://mail.python.org/mailman/listinfo/python-list
<https://mail.python.org/mailman/listinfo/python-list>

-- <br>Anthony Flury<br>anthony.flury@btinternet.com

RE: Changing calling sequence

<mailman.383.1652357938.20749.python-list@python.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18241&group=comp.lang.python#18241

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: David.Ra...@tomtom.com (David Raymond)
Newsgroups: comp.lang.python
Subject: RE: Changing calling sequence
Date: Thu, 12 May 2022 12:18:54 +0000
Lines: 23
Message-ID: <mailman.383.1652357938.20749.python-list@python.org>
References: <t5gdv7$6et$1@dont-email.me> <t5gl5r$j27$1@gioia.aioe.org>
<mailman.372.1652295680.20749.python-list@python.org>
<help-20220511200646@ram.dialup.fu-berlin.de>
<HE1PR0701MB285790560ADF047D8C6CEF0E87CB9@HE1PR0701MB2857.eurprd07.prod.outlook.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
X-Trace: news.uni-berlin.de 4EcqTVlsKfaYlVRbFQC7oAIksWiDH64zzNcKY+Ibntrw==
Return-Path: <David.Raymond@tomtom.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="1024-bit key; unprotected key"
header.d=tomtom.com header.i=@tomtom.com header.b=tS0luflY;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.043
X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'def': 0.04; 'elif': 0.09;
'else:': 0.09; 'arguments:': 0.16; 'to:addr:python-list': 0.20;
'to:name:python-list@python.org': 0.24; 'object': 0.26;
'function': 0.27; '>>>': 0.28; 'module': 0.31; 'raise': 0.31;
'year,': 0.33; 'header:In-Reply-To:1': 0.34; 'single': 0.39;
'skip:h 10': 0.61; 'skip:i 20': 0.62; 'skip:t 20': 0.66; 'day':
0.66
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=m8m36B8Vz/75rGoZRszJzh7Ei1SDTyS2hcOboKPN6kRV6RvVVXycOoOrXNhzXj8hkck4y2AJQPPcpsI6e9CMjUcLwYAVtJGWcoZJDoLABRBv0/tTr7fdhexfTMWIEH8Bb2e3oOFe0AJECsAmWdmQmrBrNFiMqu54k4ziSPiAyywyXsUzUQxWWaQwau42gNmn85MqevNcGqFLXWnbBVfLMfyG3rc/JEgZn5fXig1fPbKtDWTktrkPFe5pm2W+DH5+gVI88nMlrUZ0jMQ8Go2fOMM+FMLdYZkHM7Idh4TT0RaCXYlp/KtLr4Wq9E5PTF624+nn2KKgmOrbsAncD9By1w==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
bh=UiiRgYAPXxoZqffPQoxYjcD2ou4474mxZw4L8nTaxEc=;
b=flK7KMl3Q30VzHiD5ATua5fTBPxbZp0451DD/aIRV4PMylthdCZz+XNZkTk0JMzC3MTSLB+M+kDFMeYNXqWzX4lBH+GKD4fLciJ4p1s5jh7wSO3eKKGYv8bP6qkC2mgAh6euDbhrqW7BEqHGsGQR5o8iWnr7SI3YV9H/dXcuWzdkrBDiWqsfhgVlhIrmpl/LnYScvU+5ObW6CijotNRcAgPHjYphmr1f/9712d5/RefiQJZ2SYpXbEco/mUhSCG9hhmpCTr7pWaAFGjAJFvR0A9L/JgeXYpHXEz9ewplzL2+uP44W/0dEMN9BBUCPJv82pqnSk9tfyJ7b1Fcdw3FhA==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=tomtom.com; dmarc=pass action=none header.from=tomtom.com;
dkim=pass header.d=tomtom.com; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tomtom.com;
s=selector2;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=UiiRgYAPXxoZqffPQoxYjcD2ou4474mxZw4L8nTaxEc=;
b=tS0luflYOvf9Ugk2FRd7hNr7yPa/G2Fbar3ugCPkFm6IUnkNh/Ez9c+kblnFrO7UOscyiBowsQQhXzRmMOt8UbDZ/Q1VawY+0F3hohbMoEaBNspx2ylRJ0K6X1jJaBBI1/c6y7Yyal11oQ3z4qWf1ISvdVjiJBoEf+PaiQSesOk=
Thread-Topic: Changing calling sequence
Thread-Index: AQHYZVeOCNqinGstRkSp33CTc3J01K0Z5l0lgABgteqAAOGVQA==
In-Reply-To: <help-20220511200646@ram.dialup.fu-berlin.de>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
authentication-results: dkim=none (message not signed)
header.d=none;dmarc=none action=none header.from=tomtom.com;
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: d3edc3b1-223f-44a9-f2c0-08da34119546
x-ms-traffictypediagnostic: DB8PR07MB6313:EE_
x-microsoft-antispam-prvs: <DB8PR07MB6313CADF136254B2BE6865EB87CB9@DB8PR07MB6313.eurprd07.prod.outlook.com>
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: kA6+rwDzLCbDR5nli17HpnSjZvU8tP2l3oSXmeKb/7slkVACRyTVVplQI6krpftD1fxN2pBB9lyi5B1YfY92JdBkn4WWcl58lzfBibzoYFW22QfYUByDXWfzCkAY2FI1C+4YYGM8LQKxKXVgzGOzxv53pPgr1lcXxHzPLiTLcK6Wlp6atwkH8aQTlJsCcS1RlBcbuStVLX+JNbs5L9Y8n/9BMV5zpKhkHS/qMjkowzw2hv7yc2k8mgAJjlFRdqCNKav411FFt02WCub3FFrnpoDdK9zy74oV8FBx1AxcEwg65RbER+pD09F4VWGfR76SXt0n91l/3zl3WkPcj1YDtjNclPnlZh1TQ2bS2/Po5TzAapo+NIrRhRZ6tT1xVwGR/qc+ndN/ICSAVk+Oa9w6r2MrcjqNcmOCWMitXyBW4XLVYNYliCOSlCCcMcI6eYwIKx0Rs8AgF5TNpfqKfEtExMpKnqphkQPDBRsiH82Wf8PrfKtt9yRqzrjqO2krmp1eMI9Y6UStIjtYUYJuNn37U7XuWdWYlwlBDSjnFnNaOv1drJqBmtdjtZOYsmE1euP8/ccxRmjk9uowiuXxfxitgXWDf+0/XV1qAFxLmWDLT3R98/HXst4wiHwAiOdR6tZDwVkz/eJZMu1oxGxVFn8DRhPsp0JTFoajcF2Y4jLin/8IQ69G7gGl6jVdoqU3Qe7RHZb+EmCkdVdcwwwdiomvzg==
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:HE1PR0701MB2857.eurprd07.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230001)(4636009)(366004)(7696005)(55016003)(3480700007)(9686003)(508600001)(122000001)(33656002)(38070700005)(38100700002)(2906002)(76116006)(5660300002)(6506007)(6916009)(52536014)(66946007)(26005)(71200400001)(66556008)(8936002)(186003)(7116003)(8676002)(83380400001)(86362001)(66476007)(64756008)(316002)(66446008);
DIR:OUT; SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: AfHWpGlroxSw4XtN/FXalI74Ia11qfWaVTD7C8/wj+ez6
oL8AbIY3dMrsZwVKusf8kUBbBcooF3Sv6wM5RMMF0LMjV
zmZn3JDWAOxNxHFbLCx7wh9YkIutYwVnRtGLWOX6TLmU+
+o7bswpl7LNWTGveeskahESxCh6TrawxUus4HMEMjx21N
KVORnGtcdRjyKfVzcCk9se7aRfDQDSCx7taU+pFwqUuBA
4uN/gpDb2wSyS6JVFtNO9pecdUkAWKRB2RpEGcZWpgfCq
aHqwc86H+dyAwLP/+EmnnUUCdX9E7oeq/7vQ+RIhOqOZu
n5ddsKC4O7e3Yk08J++dW8pMLvZK5uI+FhunG7YZ05iFy
nAGEy23sjJ5Cn18GiW9ollSmSjNkWKq4NdmUxPKeGndta
p8GSos2FNT7Wi9J7MZKpDtdhmAz/2Gx56e1NkYZZn+Jul
IhY2iFpCiGZp5Nj4cRQssWYY8BWRzwNJbzkW31W9Q1s6v
lRGFlE1E7lzTfNXd6lbs2uF1maZmivmtbVqKWZOi6CF2Z
0cpbm5NtKIfe9F1Zn1VsfwlEXAueHhOIC7fNrj0CLB2Ue
tJmlt4AJyCMImIU3QKqgqvOplwI7+cbYXpqBmiA7Gl9bs
BHHJoq4oJftGvrcawaFUpwR5hvP+UnBvvf15wqianv8C4
L+E9VFYXGlXfZ3+Aejo1oel9pqZm9RG9STFlB9f8ebb1v
bP6AHL63GHotNbMuOlIojVQtMKGO8zve8OXcRnp8acnK+
LUmXoC6S+5mkplyCUvfIM+fbF3RmiWoAayxC/IVrnFY8k
ZJADpI8dVVjDApRVzbgf2KyLTq700QKipxGWqG6ELaxrj
VO2NXNZUkiVpuFr5nXQ4U4YooSdYW9QJ1QF2FnUkklk0M
Y2XUM7UD4N8F/qKdIXWMUTJUSf0a1RjPpdJS6yDN71JVt
sMlYxcnTRfmgUL9MaRncWs3e8U8DpYS4wLhAiS+gDUw23
77XHuGu/Xk3bqO4DtlLlB4m6T8xascXy9xcM3Za+v5xR0
Q0uKHRjqB1HjlcatrmJ8nblJMrX8UwdjkcDnRNNY8q8xN
NUioJH6eJKxzuTvCy0EXjoT/DVRfu5OsBzrC+Abz7vskG
LgD7P3S1tfZT6F6k1AdE/0qpB6w/15Gj0+LaTp3UwjFt+
ebYVKmd50z20EsiuvEK8LMbP1veKpj7FjY6UiMfNxwnb2
P3EXnFYiPIPxnbgB7zQHQGnmcPcJeGI0/xqeRh+ACo8ld
+Kh6UfL1TCupBMq96O+10uPVCZEQ1UBjfyqbVFFTv1OpB
4N3lmRl/YIEYR+KIFg3YmIRlmKxoVi7fahO/xLQl1Mkhj
ceyyPZhvxndMI9HAxHSDf0o+FQdS5nAIjVcF+1qDBkX3M
uOe9sNekyYmzSP32yLTBVPqiiVZMsffTOwzrfSjVfsHBr
3BX0yJo4pR8wuiWrVbbix5NTOkEG0eZN35EpTJsuJpzx/
W2zP0INb6tgOANlcht884bKR//1CBmYAX775KbTe3L3f9
OJjBTxxYnwWHaLE7N8eTcky3RJo8ompVc1VhlM6Qkh0at
Zdc79/8n36tbUdC4/8J0fUhAi4MVTZVPyRP8a1rdXeGdo
xcPt/jz5uYdR5NZwGAXJfDDf5FBtvWDS3X19sp0kZU/zt
ZgUomd6ELj/qGd69RLfpFWW89sATOO2PR/NrtWPITm0lX
CaKg014uez9HQSaApn12tyNiuuZa9nQjiUCRZX5fDO4i9
X9ReY8tRjK2X+wDc=
X-OriginatorOrg: tomtom.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: HE1PR0701MB2857.eurprd07.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: d3edc3b1-223f-44a9-f2c0-08da34119546
X-MS-Exchange-CrossTenant-originalarrivaltime: 12 May 2022 12:18:54.9733 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 374f8026-7b54-4a3a-b87d-328fa26ec10d
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: KCIoQ59LbKRgPf4wGshGUALqbYwe560vMCRdbVdULpkprmrzgkoZ28hMMhiWysOpJpVY16YNjoOQvePJ6E3GTsYyDLQqFikOpQxUeE85Fgk=
X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR07MB6313
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <HE1PR0701MB285790560ADF047D8C6CEF0E87CB9@HE1PR0701MB2857.eurprd07.prod.outlook.com>
X-Mailman-Original-References: <t5gdv7$6et$1@dont-email.me>
<t5gl5r$j27$1@gioia.aioe.org>
<mailman.372.1652295680.20749.python-list@python.org>
<help-20220511200646@ram.dialup.fu-berlin.de>
 by: David Raymond - Thu, 12 May 2022 12:18 UTC

>>def TempsOneDay(*dateComponents):
>> if len(dateComponents) == 3:
>> year, month, date = dateComponents
>> elif len(dateComponents) == 1 and isinstance(dateComponents[0], datetime.date):
>> year, month, date = (dateComponents[0].year, dateComponents[0].month, dateComponents[0].day)
>> else:
>> raise Exception("Error message here")
>
>|>>> help( TempsOneDay )
>|Help on function TempsOneDay in module __main__:
>|
>|TempsOneDay(*dateComponents)

Then just add an appropriate docstring.
>>> def TempsOneDay(*dateComponents):
... """Can be called either with 3 arguments: year, month, day
... or with a single datetime.date object"""
... if len(dateComponents) == 3:
... year, month, date = dateComponents
... elif len(dateComponents) == 1 and isinstance(dateComponents[0], datetime.date):
... year, month, date = (dateComponents[0].year, dateComponents[0].month, dateComponents[0].day)
... else:
... raise Exception("Error message here")
...
>>> help(TempsOneDay)
Help on function TempsOneDay in module __main__:
TempsOneDay(*dateComponents)
Can be called either with 3 arguments: year, month, day
or with a single datetime.date object
>>>

Re: Changing calling sequence

<t5jocr$n89$1@dont-email.me>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18248&group=comp.lang.python#18248

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: michael....@gmail.com (Michael F. Stemper)
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: Thu, 12 May 2022 14:49:46 -0500
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <t5jocr$n89$1@dont-email.me>
References: <t5gdv7$6et$1@dont-email.me>
<45cd23fe.acec.180b4b37653.Webtop.104@btinternet.com>
<mailman.374.1652299109.20749.python-list@python.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 12 May 2022 19:49:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="cec0273c7435427b294c1adbf4060b6d";
logging-data="23817"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lEpuFkKuVdEyIPOJo9pSwJH917zfpD0I="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:L2SAxZxeA9GL1qC64XVRSPzLlmM=
In-Reply-To: <mailman.374.1652299109.20749.python-list@python.org>
Content-Language: en-US
 by: Michael F. Stemper - Thu, 12 May 2022 19:49 UTC

On 11/05/2022 14.58, anthony.flury wrote:

> Why not do :
>
>       def TempsOneDayDT(date:datetime.date):
>              return TempsOneDay(date.year, date.month, date.day)
>
> No repeat of code - just a different interface to the same functionality.

Yeah, a one-line wrapper around the original function seems a
lot simpler that any of my ideas. I think that I'll even use the
name from your example.

Thanks to all who posted, as well as the many lurkers who support me
in email.

--
Michael F. Stemper
Economists have correctly predicted seven of the last three recessions.

Re: Changing calling sequence

<mailman.401.1652445530.20749.python-list@python.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18262&group=comp.lang.python#18262

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: martinp....@gmail.com (Martin Di Paola)
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: Fri, 13 May 2022 09:38:44 -0300
Lines: 33
Message-ID: <mailman.401.1652445530.20749.python-list@python.org>
References: <t5gdv7$6et$1@dont-email.me> <t5gl5r$j27$1@gioia.aioe.org>
<20220513123844.yjf34drpmhd5eakw@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
X-Trace: news.uni-berlin.de PntvJohwma+ycxKGknmSHwOc8220Kgw8ufMJ6J7vROkw==
Return-Path: <martinp.dipaola@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=Xe+Qc9m4;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.023
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; '2022': 0.05; 'pypi': 0.05;
'-0700,': 0.09; 'elif': 0.09; 'else:': 0.09; 'url:mailman': 0.15;
'args:': 0.16; 'database.': 0.16; 'skip:> 20': 0.16; 'wrote:':
0.16; 'probably': 0.17; 'message-id:@gmail.com': 0.18; 'to:addr
:python-list': 0.20; "i've": 0.22; '(and': 0.25; 'url-
ip:188.166.95.178/32': 0.25; 'url-ip:188.166.95/24': 0.25;
'url:listinfo': 0.25; 'url-ip:188.166/16': 0.25; '11,': 0.26;
'function': 0.27; 'raise': 0.31; 'url-ip:188/8': 0.31; 'keyword':
0.32; 'retrieve': 0.32; 'there': 0.33; 'year,': 0.33; 'header:In-
Reply-To:1': 0.34; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; "skip:' 10": 0.37; 'using': 0.37;
'received:209.85': 0.37; 'could': 0.38; 'received:209': 0.39;
'single': 0.39; 'use': 0.39; 'wed,': 0.39; 'something': 0.40;
'want': 0.40; 'michael': 0.60; 'search': 0.61; 'skip:o 10': 0.61;
'come': 0.62; 'skip:k 10': 0.64; 'daily': 0.65; 'skip:t 20': 0.66;
'sequence': 0.69; 'times': 0.69; 'quick': 0.77
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=date:from:to:subject:message-id:mail-followup-to:'user-agent
:references:mime-version:content-disposition:in-reply-to;
bh=xnCL+z0sq8ILCj7Aaw7gPHOqvSgFYaSBXAW0wwmKKis=;
b=Xe+Qc9m4dn9drn19WpcSm+Ou45RLHndeZ0g6FERyQh/236q9bjU6VVMv8CUiJxY3lZ
BMJo2tqcdO2Hz3G3sVMFAGCiJ8dT2m52+Ax9U3QGkFFs2+LU5mqDhJ04RWS7bviF0a9o
1kLO6xMzhphqZMAN0s2MoiQzJX4PKzKmeqjLryoreseYibTnLmqlHbSs5l4MWQOpuf9Y
Ow/ppc6mOwQujtrxTGbf/ATmODmsdAfiBliR7q2JjTD3jqyumrHVax6NTtRbNVBMaULQ
w9CONu1cSWEzxvXUX/jERD3oFFYyHRqxrrfoyDe+MSdF8IXqmIH9n3Z8NX1bI24VI6hA
PH1A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to
:'user-agent:references:mime-version:content-disposition:in-reply-to;
bh=xnCL+z0sq8ILCj7Aaw7gPHOqvSgFYaSBXAW0wwmKKis=;
b=mFRt1LUMx6H0JMHRozErrhE/TfJBe/VxEIBJrScI7bGn1PleHIWZmOYRrRO3b6AVxg
1MisPy1j9YeAp0UEdNB7GZxF9rt7TXYs4opBhPxo01ARoILtyVQ19VBvmvLp15906YkQ
zd/Ivoq43HxGQAmgQLAVHuIXGO7Qhwwv5k45EylVpwU5hD3ZyW9aLHvMphSsvSHNOwEh
QlDEtfll71QFIWMG/ZLvkC7t6udVJz1Fp3ny7L9hd5yYxrVxhAAXitpVlglKSmv2JILJ
1gWkZxNy9mGS5ZnAY4Ke/aeLBI9Q2c+dWjYGGxv30qVvBvIUnBTFII7+Gw9Jfm8cA63g
LRZg==
X-Gm-Message-State: AOAM532znAxLNQ24wzcYwQmWkSx7sXoLq342Z2Kxkqo8JpfvhNPDMTLJ
T3iSzH64ZlwBweorHwTtk4R0xzqdx6Q=
X-Google-Smtp-Source: ABdhPJxJR3TWPxW9puL17zpJUTyVWrhrjUuII1bVw7jwS+61MNcDtsE2PVpyp9xAW4fuRYPsKWGQ8g==
X-Received: by 2002:a05:6808:1807:b0:326:b642:71c6 with SMTP id
bh7-20020a056808180700b00326b64271c6mr2206405oib.129.1652445526934;
Fri, 13 May 2022 05:38:46 -0700 (PDT)
Mail-Followup-To: python-list@python.org
'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101
Thunderbird/52.5.2 Lightning/5.4.5.2'
Content-Disposition: inline
In-Reply-To: <t5gl5r$j27$1@gioia.aioe.org>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <20220513123844.yjf34drpmhd5eakw@gmail.com>
X-Mailman-Original-References: <t5gdv7$6et$1@dont-email.me>
<t5gl5r$j27$1@gioia.aioe.org>
 by: Martin Di Paola - Fri, 13 May 2022 12:38 UTC

You probably want something like overload/multiple dispatch. I quick search
on PyPI yields a 'multipledispatch' package.

I never used, however.

On Wed, May 11, 2022 at 08:36:26AM -0700, Tobiah wrote:
>On 5/11/22 06:33, Michael F. Stemper wrote:
>>I have a function that I use to retrieve daily data from a
>>home-brew database. Its calling sequence is;
>>
>>def TempsOneDay( year, month, date ):
>>
>>After using it (and its friends) for a few years, I've come to
>>realize that there are times where it would be advantageous to
>>invoke it with a datetime.date as its single argument.
>
>You could just use all keyword args:
>
>def TempsOneDay(**kwargs):
>
> if 'date' in kwargs:
> handle_datetime(kwargs['date'])
> elif 'year' in kwargs and 'month' in kwargs and 'day' in kwargs:
> handle_args(kwargs['year'], kwargs['month'], kwargs['day'])
> else:
> raise Exception("Bad keyword args")
>
>TempsOneDay(date=datetime.datetime.now)
>
>TempsOneDay(year=2022, month=11, day=30)
>
>--
>https://mail.python.org/mailman/listinfo/python-list

Re: Changing calling sequence

<mailman.414.1652566958.20749.python-list@python.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18275&group=comp.lang.python#18275

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonL...@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: Sun, 15 May 2022 10:22:15 +1200
Organization: DWM
Lines: 73
Message-ID: <mailman.414.1652566958.20749.python-list@python.org>
References: <t5gdv7$6et$1@dont-email.me>
<671ca838-f59e-4739-f795-4f328399ab9f@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 3sY0q3FAlktB7KsjSPsApQC/0/E/tZG/mYC/G/fO/ATw==
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=kqsVfe+T; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'looks': 0.02; 'argument':
0.04; 'def': 0.04; '(for': 0.05; 'bunch': 0.05; '=dn': 0.09;
'approach?': 0.09; 'approaches': 0.09; 'construct': 0.09;
'converting': 0.09; 'datetime': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'int': 0.09; 'much,': 0.09; 'obviously': 0.09; 'memory':
0.15; '(ie': 0.16; '10?': 0.16; 'although,': 0.16; 'approach,':
0.16; 'arguments': 0.16; 'assuming': 0.16; 'case).': 0.16;
'code),': 0.16; 'database.': 0.16; 'decreases': 0.16; 'fourth':
0.16; 'invoke': 0.16; 'message-id:@DancesWithMice.info': 0.16;
'option.': 0.16; 'readability': 0.16; 'received:51.254': 0.16;
'received:51.254.211': 0.16; 'received:51.254.211.219': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16; 'reminded':
0.16; 'rewrite': 0.16; 'sole': 0.16; 'tuple': 0.16; 'whilst':
0.16; 'year)': 0.16; 'wrote:': 0.16; 'python': 0.16; 'probably':
0.17; 'to:addr:python-list': 0.20; "i've": 0.22; 'version': 0.23;
'code': 0.23; "i'd": 0.24; '(and': 0.25; 'anything': 0.25;
'seems': 0.26; 'cover': 0.26; 'task': 0.26; "isn't": 0.27;
'function': 0.27; 'error': 0.29; 'header:User-Agent:1': 0.30;
'takes': 0.31; 'header:Organization:1': 0.31; 'anybody': 0.32;
'here,': 0.32; 'keyword': 0.32; 'realize': 0.32; 'retrieve': 0.32;
'said,': 0.32; "wouldn't": 0.32; 'but': 0.32; "i'm": 0.33; "i'll":
0.33; 'there': 0.33; 'year,': 0.33; 'work.': 0.34; 'header:In-
Reply-To:1': 0.34; 'following': 0.35; "we're": 0.35; 'change':
0.36; 'currently': 0.37; 'really': 0.37; 'using': 0.37;
'received:192.168': 0.37; 'could': 0.38; 'least': 0.39; 'single':
0.39; 'list': 0.39; 'use': 0.39; 'still': 0.40; 'michael': 0.60;
'above': 0.62; 'skip:i 20': 0.62; 'lower': 0.62; 'come': 0.62;
'limited': 0.62; 'once': 0.63; 'skip:m 20': 0.63; 'skip:k 10':
0.64; 'definition': 0.64; 'received:51': 0.64; 'upon': 0.64;
'policy.': 0.65; 'daily': 0.65; 'similar': 0.65; 'touch': 0.65;
'well': 0.65; 'received:userid': 0.66; 'matter': 0.68;
'discussing': 0.69; 'only.': 0.69; 'sequence': 0.69; 'varying':
0.69; 'times': 0.69; 'above,': 0.70; 'choice': 0.76; 'signature':
0.76; 'changed,': 0.84; 'method,': 0.84; 'readability.': 0.84;
'touching': 0.84
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud E0F69B3CA
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1652566956;
bh=t9hePsT6qiHi5NrbDsvl4e6n0Waf32z5OH2VVmPpJ9s=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=kqsVfe+TJtzT/+WrS7JwPDE9hnZXEqcA8E5GBKgiC6zDrUljdKrxK1sYwWZRrcngN
v9iNrI326SQ1FQyzGaoo3Q4D4TM4qcVUCxU5y0wx26TARp6HUg973LjwHLfaQmZLqf
mNLoM+H4xCbxy5Xqf+blSl4GQdtd+AB3OistUtGii9h4u9/awjppVGaoOR/p9Q/Qia
x+JAweYxD03bkkoYUIBt7XmEgRaFQr4KtjaUy5e67QYZyWsVlBnb9qHy1a29w2oR6T
2tklMJt0masJaJgjh/b2czZYRNQnfdLCZmaIx5L9uonYLt2NqnjAXBXukKY24GzrbD
RjziQ7NZp3sXw==
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on vps517507.ovh.net
X-Spam-Level:
X-Spam-Status: No, score=-3.8 required=5.0 tests=ALL_TRUSTED,BAYES_00,
DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,NICE_REPLY_A,T_SCC_BODY_TEXT_LINE
autolearn=ham autolearn_force=no version=3.4.0
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud 29732B3C5
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1652566955;
bh=t9hePsT6qiHi5NrbDsvl4e6n0Waf32z5OH2VVmPpJ9s=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=jX1njcB8lCDIKN42U1GY2x0v5tLMYmYsQpvaPIwVw0xu8FQ+DV05NXIujrP4Rda4m
5vzk7cnw/zreXHPj5l+ZwledWsNQzIZ4J9dc9fo7/ul1xo2V7ScgR4JyZTAl3ZAWsA
xkun+yLCOIYZ9sCezawo13O2AT4eRSWlk+XhWhhgB7OmhCGM8iExliT2x4Ohsqr5uB
Df0AcCXc33xTc9hKFFNRvgE1ZF6K5SO4kkezxV/GJlj3v0+OAXa/pIDuIlAKEwZCly
Hj0EtgxY7SvmZwF/89ld8xCMUJcGb4aiNJMM5WyB8guAvx7N6VpH8Cof5p4RyqPtZC
oeB7D6w66vMzw==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Content-Language: en-GB
In-Reply-To: <t5gdv7$6et$1@dont-email.me>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <671ca838-f59e-4739-f795-4f328399ab9f@DancesWithMice.info>
X-Mailman-Original-References: <t5gdv7$6et$1@dont-email.me>
 by: dn - Sat, 14 May 2022 22:22 UTC

On 12/05/2022 01.33, Michael F. Stemper wrote:
> I have a function that I use to retrieve daily data from a
> home-brew database. Its calling sequence is;
>
> def TempsOneDay( year, month, date ):
>
> After using it (and its friends) for a few years, I've come to
> realize that there are times where it would be advantageous to
> invoke it with a datetime.date as its single argument.
>
> As far as I can tell, there are three ways for me to proceed:
> 1. Write a similar function that takes a single datetime.date
>    as its argument.
> 2. Rewrite the existing function so that it takes a single
>    argument, which can be either a tuple of (year,month,date)
>    or a datetime.date argument.
> 3. Rewrite the existing function so that its first argument
>    can be either an int (for year) or a datetime.date. The
>    existing month and date arguments would be optional, with
>    default=None. But, if the first argument is an int, and
>    either of month or date is None, an error would be raised.
>
> The first would be the simplest. However, it is obviously WET
> rather than DRY.
>
> The second isn't too bad, but a change like this would require that
> I find all places that the function is currently used and insert a
> pair of parentheses. Touching this much code is risky, as well
> as being a bunch of work. (Admittedly, I'd only do it once.)
>
> The third is really klunky, but wouldn't need to touch anything
> besides this function.
>
> What are others' thoughts? Which of the approaches above looks
> least undesirable (and why)? Can anybody see a fourth approach?

Reading the above, it seems that the options are limited to using
positional-arguments only. Because I keep tripping-over my long, grey,
beard; I'm reminded that relying upon my/human memory is, um, unreliable
(at least in my case). Accordingly, by the time a function's definition
reaches three parameters, I'll be converting it to use keyword-arguments
as a matter of policy. YMMV!

Remember: if keyword arguments are not used (ie existing/legacy code),
Python will still use positional logic.

Once the function's signature has been changed, we could then add
another keyword-parameter to cover the datetime option.

That said, a function which starts with a list of ifs-buts-and-maybes*
which are only there to ascertain which set of arguments have been
provided by the calling-routine; obscures the purpose/responsibility of
the function and decreases its readability (perhaps not by much, but
varying by situation).

Accordingly, if the function is actually a method, recommend following
@Stefan's approach, ie multiple-constructors. Although, this too can
result in lower readability.

Assuming it is a function, and that there are not many alternate
APIs/approaches (here we're discussing only two), I'd probably create a
wrapper-function which has the sole task of re-stating the datetime
whilst calling the existing three-parameter function. The readability
consideration here, is to make a good choice of (new) function-name!

* Python version >= 10? Consider using match-case construct keyed on
parameter-type
--
Regards,
=dn

Re: Changing calling sequence

<mailman.415.1652571274.20749.python-list@python.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18276&group=comp.lang.python#18276

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: 2QdxY4Rz...@potatochowder.com
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: Sat, 14 May 2022 18:34:23 -0500
Lines: 25
Message-ID: <mailman.415.1652571274.20749.python-list@python.org>
References: <t5gdv7$6et$1@dont-email.me>
<671ca838-f59e-4739-f795-4f328399ab9f@DancesWithMice.info>
<YoA8f6siH0NlVXGX@scrozzle>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de AWQd42biRKkvE6nkt7V7IgqyH1GEc0LzJ21uUKwBDGaQ==
Return-Path: <2QdxY4RzWzUUiLuE@potatochowder.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.014
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'methods,': 0.09; 'much,':
0.09; 'received:78': 0.09; 'although,': 0.16; 'approach,': 0.16;
'arguments': 0.16; 'assuming': 0.16; 'decreases': 0.16;
'from:addr:2qdxy4rzwzuuilue': 0.16; 'from:addr:potatochowder.com':
0.16; 'functions,': 0.16; 'message-id:@scrozzle': 0.16;
'procedures,': 0.16; 'readability': 0.16; 'received:136.243':
0.16; 'received:78.46': 0.16; 'received:www458.your-server.de':
0.16; 'received:your-server.de': 0.16; 'use?': 0.16; 'wrote:':
0.16; 'to:addr:python-list': 0.20; 'received:de': 0.23; '(and':
0.25; 'function': 0.27; 'approach': 0.31; 'wondering': 0.31;
'guess': 0.32; 'programmers': 0.32; 'received:136': 0.32; 'said,':
0.32; 'but': 0.32; 'there': 0.33; 'same': 0.34; 'header:In-Reply-
To:1': 0.34; 'following': 0.35; 'list': 0.39; "there's": 0.61;
'skip:i 20': 0.62; 'lower': 0.62; 'skip:m 20': 0.63; 'lead': 0.67;
'generally': 0.67; 'varying': 0.69; 'them,': 0.70;
'charset:iso-8859-1': 0.73; 'method,': 0.84; 'readability.': 0.84;
'received:70': 0.84
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <671ca838-f59e-4739-f795-4f328399ab9f@DancesWithMice.info>
X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com
X-Virus-Scanned: Clear (ClamAV 0.103.5/26541/Sat May 14 10:03:48 2022)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <YoA8f6siH0NlVXGX@scrozzle>
X-Mailman-Original-References: <t5gdv7$6et$1@dont-email.me>
<671ca838-f59e-4739-f795-4f328399ab9f@DancesWithMice.info>
 by: 2QdxY4Rz...@potatochowder.com - Sat, 14 May 2022 23:34 UTC

On 2022-05-15 at 10:22:15 +1200,
dn <PythonList@DancesWithMice.info> wrote:

> That said, a function which starts with a list of ifs-buts-and-maybes*
> which are only there to ascertain which set of arguments have been
> provided by the calling-routine; obscures the purpose/responsibility
> of the function and decreases its readability (perhaps not by much,
> but varying by situation).

Agreed.

> Accordingly, if the function is actually a method, recommend following
> @Stefan's approach, ie multiple-constructors. Although, this too can
> result in lower readability.

(Having proposed that approach myself (and having used it over the
decades for functions, methods, procedures, constructors, ...), I also
agree.)

Assuming good names,¹ how can this lead to lower readability? I guess
if there's too many of them, or programmers have to start wondering
which one to use? Or is this in the same generally obfuscating category
as the ifs-buts-and-maybes at the start of a function?

¹ and properly invalidated caches

Re: Changing calling sequence

<mailman.417.1652588790.20749.python-list@python.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18278&group=comp.lang.python#18278

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: PythonL...@DancesWithMice.info (dn)
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: Sun, 15 May 2022 16:26:02 +1200
Organization: DWM
Lines: 88
Message-ID: <mailman.417.1652588790.20749.python-list@python.org>
References: <t5gdv7$6et$1@dont-email.me>
<671ca838-f59e-4739-f795-4f328399ab9f@DancesWithMice.info>
<YoA8f6siH0NlVXGX@scrozzle>
<aabc28cb-d91c-a855-8d49-257b62e02ffd@DancesWithMice.info>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de SK931814SNYQfGVuCZVG6QqLxPBG1rXShYRKxPVZtkhg==
Return-Path: <PythonList@DancesWithMice.info>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=danceswithmice.info header.i=@danceswithmice.info
header.b=T7aoalCU; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.019
X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'variable': 0.05;
'architecture': 0.07; '=dn': 0.09; 'example:': 0.09;
'from:addr:danceswithmice.info': 0.09; 'from:addr:pythonlist':
0.09; 'interfaces': 0.09; 'methods,': 0.09; 'much,': 0.09; 'url-
ip:151.101.0.223/32': 0.09; 'url-ip:151.101.128.223/32': 0.09;
'url-ip:151.101.192.223/32': 0.09; 'url-ip:151.101.64.223/32':
0.09; 'although,': 0.16; 'approach,': 0.16; 'arguments': 0.16;
'assuming': 0.16; 'decreases': 0.16; 'expectation': 0.16;
'functions,': 0.16; 'interface,': 0.16; 'message-
id:@DancesWithMice.info': 0.16; 'procedures,': 0.16;
'readability': 0.16; 'received:51.254': 0.16;
'received:51.254.211': 0.16; 'received:51.254.211.219': 0.16;
'received:cloud': 0.16; 'received:rangi.cloud': 0.16; 'skip:. 20':
0.16; 'url:peps': 0.16; 'use?': 0.16; 'wrote:': 0.16; 'to:addr
:python-list': 0.20; "i've": 0.22; 'maybe': 0.22; 'code': 0.23;
'(and': 0.25; 'actual': 0.25; 'anyone': 0.25; 'interests': 0.26;
'interface': 0.26; 'function': 0.27; 'sense': 0.28; 'example,':
0.28; 'header:User-Agent:1': 0.30; 'approach': 0.31; 'comment':
0.31; 'convention': 0.31; 'module': 0.31; 'header:Organization:1':
0.31; 'wondering': 0.31; 'guess': 0.32; 'programmers': 0.32;
'said,': 0.32; 'signal': 0.32; "wouldn't": 0.32; 'but': 0.32;
'there': 0.33; 'same': 0.34; 'header:In-Reply-To:1': 0.34;
'url:)': 0.35; 'usual': 0.35; 'words': 0.35; 'following': 0.35;
'those': 0.36; 'class': 0.37; 'received:192.168': 0.37; 'could':
0.38; 'read': 0.38; 'quite': 0.39; 'least': 0.39; 'necessary':
0.39; 'list': 0.39; 'statistical': 0.40; 'want': 0.40; 'should':
0.40; 'four': 0.60; 'remember': 0.61; 'skip:h 10': 0.61;
"there's": 0.61; 'skip:i 20': 0.62; 'lower': 0.62; 'url-
ip:151.101.0/24': 0.62; 'url-ip:151.101.128/24': 0.62; 'url-
ip:151.101.192/24': 0.62; 'url-ip:151.101.64/24': 0.62; 'follow':
0.62; 'skip:o 20': 0.63; 'skip:m 20': 0.63; 'between': 0.63;
'skip:k 10': 0.64; 'down': 0.64; 'extend': 0.64; 'received:51':
0.64; 'applicable': 0.65; 'look': 0.65; 'well': 0.65; 'improve':
0.66; 'received:userid': 0.66; 'time.': 0.66; 'earlier': 0.67;
'lead': 0.67; 'generally': 0.67; 'further': 0.69; 'varying': 0.69;
'them,': 0.70; 'relevant': 0.73; 'skip:f 20': 0.75; 'choices':
0.84; 'method,': 0.84; 'readability.': 0.84; 'realise': 0.84;
'thus,': 0.84; 'criticism': 0.91
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud A22AC347D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1652588788;
bh=rnGUZO3TLfSKFwApEWsgr0Q8dCmGBbq3rjFlNRuuXBM=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=T7aoalCU3lZctwGpTfNOox3zHb+m++RyyUf9g0PykhzPaingvKINjyCd1Ek4hupOT
6Jjrgmq2Q21DHaoxp6+KY+lpx3j03amAi69uBojs7030KGKysXoAKuPyWOdzBKfZjB
EfGDHIaiOPbvrQQJGgKM/weSggF8aIuZ5jjmv02YoEMmxomGJ0uWEEOb50au9YazcT
ezvQkyycDntRHeeCCQ+KMUvEg1TFbIkw/acLtNPcI4QwXNw0s+NVaZG6Su6kou52yx
wG+Lo5S4VdLljiJJhtwyukSNhZd+l6j9flUOVSdmfIpx7hnmzSNldvEtEBHC8UyzUq
HAY2HE++9zUXg==
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on vps517507.ovh.net
X-Spam-Level:
X-Spam-Status: No, score=-3.8 required=5.0 tests=ALL_TRUSTED,BAYES_00,
DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,NICE_REPLY_A,T_SCC_BODY_TEXT_LINE
autolearn=ham autolearn_force=no version=3.4.0
DKIM-Filter: OpenDKIM Filter v2.11.0 vps.rangi.cloud 7FE3B341D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=danceswithmice.info;
s=staff; t=1652588787;
bh=rnGUZO3TLfSKFwApEWsgr0Q8dCmGBbq3rjFlNRuuXBM=;
h=Date:Subject:To:References:From:In-Reply-To:From;
b=QmPlYi5Lev6SoZmoD7VFjvcreoI3XgBhWVYy8uWamhPCqAJZbN7y/OrpmnGFwtDMD
viObsPcCYocD2++4A4/HwOFqXO/In+Q3cAOotBiI6bLEHcbNZR4bqpq3QMhAsySx0I
2FRYgFXlS3dH0EbPNJYKb/tgUWaboAvsWzqzYhRM2PeqquuVAagp8yjxLYbpVxUUBG
uoPE9TXuMQRnh/gOP6xWlf56hUpvkEQ1hhwc7bEpGJtJObTBVUuk/Y4HV5ZlJ2tw45
89LmST4YHeMmQLke9DfeEfTogo/fe5bjqiOgwxrQ7NX2IM3IgADgGw4jLMlSMqFiwT
xwXApuYrs2TxQ==
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.8.1
Content-Language: en-GB
In-Reply-To: <YoA8f6siH0NlVXGX@scrozzle>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <aabc28cb-d91c-a855-8d49-257b62e02ffd@DancesWithMice.info>
X-Mailman-Original-References: <t5gdv7$6et$1@dont-email.me>
<671ca838-f59e-4739-f795-4f328399ab9f@DancesWithMice.info>
<YoA8f6siH0NlVXGX@scrozzle>
 by: dn - Sun, 15 May 2022 04:26 UTC

On 15/05/2022 11.34, 2QdxY4RzWzUUiLuE@potatochowder.com wrote:
> On 2022-05-15 at 10:22:15 +1200,
> dn <PythonList@DancesWithMice.info> wrote:
>
>> That said, a function which starts with a list of ifs-buts-and-maybes*
>> which are only there to ascertain which set of arguments have been
>> provided by the calling-routine; obscures the purpose/responsibility
>> of the function and decreases its readability (perhaps not by much,
>> but varying by situation).
>
> Agreed.
>
>> Accordingly, if the function is actually a method, recommend following
>> @Stefan's approach, ie multiple-constructors. Although, this too can
>> result in lower readability.
>
> (Having proposed that approach myself (and having used it over the
> decades for functions, methods, procedures, constructors, ...), I also
> agree.)
>
> Assuming good names,¹ how can this lead to lower readability? I guess
> if there's too many of them, or programmers have to start wondering
> which one to use? Or is this in the same generally obfuscating category
> as the ifs-buts-and-maybes at the start of a function?
>
> ¹ and properly invalidated caches

Allow me to extend the term "readability" to include "comprehension".
Then add the statistical expectation that a class has only __init__().
Thus, assuming this is the first time (or, ... for a while) that the
class is being employed, one has to read much further to realise that
there are choices of constructor.

Borrowing from the earlier example:

> This would be quite pythonic. For example, "datetime.date"
> has .fromtimestamp(timestamp), .fromordinal(ordinal),
> .fromisoformat(date_string), ...

Please remember that this is only relevant if the function is actually a
module - which sense does not appear from the OP (IMHO).

The alternatives' names are well differentiated and (apparently#)
appropriately named*.

* PEP-008 hobgoblins will quote:
"Function names should be lowercase, with words separated by underscores
as necessary to improve readability.
Variable names follow the same convention as function names."
- but this is a common observation/criticism of code that has been in
the PSL for a long time.

# could also criticise as not following the Software Craftsmanship/Clean
Code ideal of 'programming to the interface rather than the
implementation' - which we see in PEP-008 as "usage rather than
implementation"
(but please don't ask me how to differentiate between them, given that
the only reason for the different interfaces is the
function's/parameters' implementation!)

NB usual caveats apply to PEP-008 quotations!

So, I agree with you - it comes down to those pernicious
'ifs-buts-and-maybes'. If the interface/parameter-processing starts to
obfuscate the function's actual purpose, maybe it can be 'farmed-out' to
a helper-function. However, that would start to look very much like the
same effort (and comprehension-challenge) as having a wrapper-function!

Continuing the 'have to read further' criticism (above), it could
equally-well be applied to my preference for keyword-arguments, in that
I've suggested defining four parameters but the user will only call the
function with either three or one argument(s). Could this be described
as potentially-confusing?

Given that the OP wouldn't want to have to redefine the existing
interface, the next comment may not be applicable - but in the interests
of completeness: anyone contemplating such architecture might like to
consider "Single-dispatch generic functions"
(https://peps.python.org/pep-0443/). At least the decorators signal that
there are alternative-choices...
--
Regards,
=dn

Re: Changing calling sequence

<mailman.418.1652589863.20749.python-list@python.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18279&group=comp.lang.python#18279

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: Sun, 15 May 2022 14:44:09 +1000
Lines: 110
Message-ID: <mailman.418.1652589863.20749.python-list@python.org>
References: <t5gdv7$6et$1@dont-email.me>
<671ca838-f59e-4739-f795-4f328399ab9f@DancesWithMice.info>
<YoA8f6siH0NlVXGX@scrozzle>
<aabc28cb-d91c-a855-8d49-257b62e02ffd@DancesWithMice.info>
<CAPTjJmo1MYW4H+fCYfHwLve1tqm3EC0DY6c6M0kQZJhYvpmmwg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de WUZY9QNOYepLZ/LQfPBTZQXjigAtOu+I1rMRiaLC/8sg==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=oENY14zo;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.025
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'argument': 0.04; '2022':
0.05; 'variable': 0.05; 'pep': 0.07; 'string': 0.07; 'sun,': 0.07;
'"as': 0.09; 'consistency': 0.09; 'construct': 0.09; 'depend':
0.09; 'example:': 0.09; 'interfaces': 0.09; 'methods,': 0.09;
'much,': 0.09; '(eg': 0.16; '14:27,': 0.16; 'although,': 0.16;
'approach,': 0.16; 'arguments': 0.16; 'assuming': 0.16; 'chrisa':
0.16; 'decreases': 0.16; 'expectation': 0.16; 'from:addr:rosuav':
0.16; 'from:name:chris angelico': 0.16; 'functions,': 0.16;
'instance': 0.16; 'personally,': 0.16; 'procedures,': 0.16;
'readability': 0.16; 'skip:. 20': 0.16; 'use?': 0.16; 'wrapper':
0.16; 'wrote:': 0.16; 'problem': 0.16; 'api': 0.17; "aren't":
0.19; 'calls': 0.19; 'to:addr:python-list': 0.20; "i've": 0.22;
'code': 0.23; "i'd": 0.24; '(and': 0.25; 'depends': 0.25;
'interface': 0.26; 'library': 0.26; 'object': 0.26; 'function':
0.27; 'sense': 0.28; 'example,': 0.28; 'recently': 0.29; 'takes':
0.31; 'approach': 0.31; 'convention': 0.31; 'looked': 0.31;
'module': 0.31; 'wondering': 0.31; 'guess': 0.32; 'here,': 0.32;
'objects': 0.32; 'obtain': 0.32; 'programmers': 0.32; 'said,':
0.32; 'split': 0.32; 'message-id:@mail.gmail.com': 0.32; 'but':
0.32; 'there': 0.33; 'same': 0.34; 'mean': 0.34; 'header:In-Reply-
To:1': 0.34; 'received:google.com': 0.34; 'fine': 0.35; 'usual':
0.35; 'words': 0.35; 'yes,': 0.35; 'following': 0.35;
'from:addr:gmail.com': 0.35; 'main': 0.37; "it's": 0.37;
'received:209.85': 0.37; 'class': 0.37; 'way': 0.38; 'could':
0.38; 'read': 0.38; 'received:209': 0.39; 'two': 0.39; 'quite':
0.39; 'added': 0.39; 'least': 0.39; 'necessary': 0.39; 'single':
0.39; 'list': 0.39; 'methods': 0.39; '(see': 0.40; 'statistical':
0.40; 'both': 0.40; 'should': 0.40; 'four': 0.60; 'potential':
0.60; 'remember': 0.61; "there's": 0.61; 'skip:i 20': 0.62;
'lower': 0.62; 'point.': 0.62; 'here': 0.62; 'follow': 0.62;
'skip:o 20': 0.63; 'skip:m 20': 0.63; 'between': 0.63; 'skip:k
10': 0.64; 'document.': 0.64; 'extend': 0.64; 'imagine': 0.64;
'well': 0.65; 'required': 0.65; 'improve': 0.66; 'time.': 0.66;
'earlier': 0.67; 'lead': 0.67; 'body': 0.67; 'generally': 0.67;
'further': 0.69; 'varying': 0.69; 'times': 0.69; 'them,': 0.70;
'relevant': 0.73; 'name,': 0.75; 'skip:f 20': 0.75; 'signature':
0.76; 'major': 0.78; 'choices': 0.84; 'cleaner': 0.84; 'method,':
0.84; 'notably': 0.84; 'operate.': 0.84; 'readability.': 0.84;
'realise': 0.84; 'rules,': 0.84; 'say,': 0.84; 'strings': 0.84;
'thus,': 0.84; 'criticism': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:content-transfer-encoding;
bh=lQdy751azkdKNBRg5C7L6Zk6QHbuGK+koyTyRS9rLY4=;
b=oENY14zoKccz4qjT/AB/c+F0wbqhc58+imOjPulOI4aYJglImPmBLzHcMB6okN08z9
ZAdJE0CaOTo55rZdCZA1a0wF1naR7xkEIlrT9d5jPYPlbadSuHqmeN+LXCIU0tKBTs43
CCn7GLgaoXjXI+fP4qbgmarEdEKrrjNqVeV/AJVOWE25ONQWGGgzugOqcaLNzmemLDsk
qYtql8MnT+2wriZkscZT9FQDs6RWJcc2Mad7OznL83lQUdxhbS1celTjc4sghjRjnP53
m02vS3dfaDnILMtHRLL4O7/SvRZUuarIPvLXxDQepb7Pt9iXetAJC7ViF4wsxK4UeA0w
x4fQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:content-transfer-encoding;
bh=lQdy751azkdKNBRg5C7L6Zk6QHbuGK+koyTyRS9rLY4=;
b=I+7CJLfNUwmmqkSNEz1rLMcX6K6vnel0r+FjhNfUnl5AKKPydjGOPtlchAlbUCwNRd
n5NWZt0QHaRQBN4c5jGUCpWllst8m8o+wx69lEI14e6/6cGaHKe1GDh50V/GbHibNT7w
1Ask1htlRE3uN26fEtND1jw9OytPUFv+fP1FKomkvTMJYS9ZDDXj+NT5mXkAwcWimYcm
/t6cEgxpbXGCV+HsKxsOnGL5p4XDc464cipec2HyCBuQiOeTTaqmXFb7sod+lE6QQtwi
D/u2cxClF1KPu+89vpw3EoHXhgu3MH5AM32PDyABApoi/xjG2fPVI2/sjnAT6cqAg1DO
ER+g==
X-Gm-Message-State: AOAM5326sFjNEY+mMBwS11drVU1wamsUdZs6JpH85muqfl0sJHhekEZj
QGpZ7LsOcnFhmFq6vIRGyJsDudR91A0tdmIibpxsDeeY
X-Google-Smtp-Source: ABdhPJyBUZilGzlheulOAiwhrXrdGjmKMFgfcEaJh8Vfly7IVEhXjU3Dg3RBFX/wrhpvL1T8LXROCryLpoZ0agxlxOo=
X-Received: by 2002:a05:600c:1e17:b0:394:547c:e5a6 with SMTP id
ay23-20020a05600c1e1700b00394547ce5a6mr11215328wmb.203.1652589861460; Sat, 14
May 2022 21:44:21 -0700 (PDT)
In-Reply-To: <aabc28cb-d91c-a855-8d49-257b62e02ffd@DancesWithMice.info>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <CAPTjJmo1MYW4H+fCYfHwLve1tqm3EC0DY6c6M0kQZJhYvpmmwg@mail.gmail.com>
X-Mailman-Original-References: <t5gdv7$6et$1@dont-email.me>
<671ca838-f59e-4739-f795-4f328399ab9f@DancesWithMice.info>
<YoA8f6siH0NlVXGX@scrozzle>
<aabc28cb-d91c-a855-8d49-257b62e02ffd@DancesWithMice.info>
 by: Chris Angelico - Sun, 15 May 2022 04:44 UTC

On Sun, 15 May 2022 at 14:27, dn <PythonList@danceswithmice.info> wrote:
>
> On 15/05/2022 11.34, 2QdxY4RzWzUUiLuE@potatochowder.com wrote:
> > On 2022-05-15 at 10:22:15 +1200,
> > dn <PythonList@DancesWithMice.info> wrote:
> >
> >> That said, a function which starts with a list of ifs-buts-and-maybes*
> >> which are only there to ascertain which set of arguments have been
> >> provided by the calling-routine; obscures the purpose/responsibility
> >> of the function and decreases its readability (perhaps not by much,
> >> but varying by situation).
> >
> > Agreed.
> >
> >> Accordingly, if the function is actually a method, recommend following
> >> @Stefan's approach, ie multiple-constructors. Although, this too can
> >> result in lower readability.
> >
> > (Having proposed that approach myself (and having used it over the
> > decades for functions, methods, procedures, constructors, ...), I also
> > agree.)
> >
> > Assuming good names,¹ how can this lead to lower readability? I guess
> > if there's too many of them, or programmers have to start wondering
> > which one to use? Or is this in the same generally obfuscating category
> > as the ifs-buts-and-maybes at the start of a function?
> >
> > ¹ and properly invalidated caches
>
> Allow me to extend the term "readability" to include "comprehension".
> Then add the statistical expectation that a class has only __init__().

(Confusing wording here: a class usually has far more than just
__init__, but I presume you mean that the signature of __init__ is the
only way to construct an object of that type.)

> Thus, assuming this is the first time (or, ... for a while) that the
> class is being employed, one has to read much further to realise that
> there are choices of constructor.

Yeah. I would generally say, though, that any classmethod should be
looked at as a potential alternate constructor, or at least an
alternate way to obtain objects (eg preconstructed objects with
commonly-used configuration - imagine a SecuritySettings class with a
classmethod to get different defaults).

> Borrowing from the earlier example:
>
> > This would be quite pythonic. For example, "datetime.date"
> > has .fromtimestamp(timestamp), .fromordinal(ordinal),
> > .fromisoformat(date_string), ...
>
> Please remember that this is only relevant if the function is actually a
> module - which sense does not appear from the OP (IMHO).
>
> The alternatives' names are well differentiated and (apparently#)
> appropriately named*.
>
>
> * PEP-008 hobgoblins will quote:
> "Function names should be lowercase, with words separated by underscores
> as necessary to improve readability.

Note the "as necessary". Underscores aren't required when readability
is fine without them (see for instance PEP 616, which recently added
two methods to strings "removeprefix" and "removesuffix", no
underscores - part of the argument here was consistency with other
string methods, but it's also not a major problem for readability
here).

> Variable names follow the same convention as function names."
> - but this is a common observation/criticism of code that has been in
> the PSL for a long time.
>
> # could also criticise as not following the Software Craftsmanship/Clean
> Code ideal of 'programming to the interface rather than the
> implementation' - which we see in PEP-008 as "usage rather than
> implementation"
> (but please don't ask me how to differentiate between them, given that
> the only reason for the different interfaces is the
> function's/parameters' implementation!)
>
> NB usual caveats apply to PEP-008 quotations!

Notably here, the caveat that PEP 8 is not a permanent and unchanging
document. It is advice, not rules, and not all code in the standard
library fully complies with its current recommendations.

> Continuing the 'have to read further' criticism (above), it could
> equally-well be applied to my preference for keyword-arguments, in that
> I've suggested defining four parameters but the user will only call the
> function with either three or one argument(s). Could this be described
> as potentially-confusing?

Yes, definitely. Personally, I'd split it into two, one that takes the
existing three arguments (preferably with the same name, for
compatibility), and one with a different name that takes just the one
arg. That could be a small wrapper that calls the original, or the
original could become a wrapper that calls the new one, or the main
body could be refactored into a helper that they both call. It all
depends what makes the most sense internally, because that's not part
of the API at that point.

But it does depend on how the callers operate. Sometimes it's easier
to have a single function with switchable argument forms, other times
it's cleaner to separate them.

ChrisA

Re: Changing calling sequence

<mailman.419.1652620839.20749.python-list@python.org>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18280&group=comp.lang.python#18280

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: 2QdxY4Rz...@potatochowder.com
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: Sun, 15 May 2022 08:20:34 -0500
Lines: 119
Message-ID: <mailman.419.1652620839.20749.python-list@python.org>
References: <t5gdv7$6et$1@dont-email.me>
<671ca838-f59e-4739-f795-4f328399ab9f@DancesWithMice.info>
<YoA8f6siH0NlVXGX@scrozzle>
<aabc28cb-d91c-a855-8d49-257b62e02ffd@DancesWithMice.info>
<CAPTjJmo1MYW4H+fCYfHwLve1tqm3EC0DY6c6M0kQZJhYvpmmwg@mail.gmail.com>
<YoD+ImdI+VJODwXD@scrozzle>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de F2gsgCNBTZOqFDHES6bP2gVk+kdAQXBzd5JZEMFKnSkg==
Return-Path: <2QdxY4RzWzUUiLuE@potatochowder.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; '2022':
0.05; 'class,': 0.05; ';-)': 0.07; 'clarify': 0.07; 'sun,': 0.07;
'tests': 0.07; ':-)': 0.09; 'angelico': 0.09; 'code?': 0.09;
'depend': 0.09; 'example:': 0.09; 'imo,': 0.09; 'methods,': 0.09;
'module.': 0.09; 'much,': 0.09; 'received:78': 0.09; 'sometimes,':
0.09; 'talks': 0.14; '"but': 0.16; '(eg': 0.16; '14:27,': 0.16;
'although,': 0.16; 'another.': 0.16; 'approach,': 0.16;
'arguments': 0.16; 'assuming': 0.16; 'decreases': 0.16;
'document,': 0.16; 'expectation': 0.16;
'from:addr:2qdxy4rzwzuuilue': 0.16; 'from:addr:potatochowder.com':
0.16; 'functions,': 0.16; 'instance': 0.16; 'message-
id:@scrozzle': 0.16; 'object,': 0.16; 'personally,': 0.16;
'procedures,': 0.16; 'readability': 0.16; 'reason.': 0.16;
'received:136.243': 0.16; 'received:78.46': 0.16;
'received:78.46.172': 0.16; 'received:78.46.172.2': 0.16;
'received:sslproxy05.your-server.de': 0.16; 'received:www458.your-
server.de': 0.16; 'received:your-server.de': 0.16; 'scream': 0.16;
'skip:. 20': 0.16; 'spot': 0.16; 'testers': 0.16; 'use?': 0.16;
'wrapper': 0.16; 'wrote:': 0.16; 'api': 0.17; 'probably': 0.17;
'calls': 0.19; 'to:addr:python-list': 0.20; 'written': 0.22;
"i've": 0.22; "what's": 0.22; 'code': 0.23; 'received:de': 0.23;
"i'd": 0.24; 'idea': 0.24; '(and': 0.25; 'depends': 0.25; 'stuff':
0.25; 'opening': 0.26; 'bit': 0.27; 'function': 0.27; 'chris':
0.28; 'sense': 0.28; 'example,': 0.28; 'takes': 0.31; 'approach':
0.31; 'looked': 0.31; 'module': 0.31; 'wondering': 0.31; 'think':
0.32; 'good.': 0.32; 'guess': 0.32; 'here,': 0.32; 'keyword':
0.32; 'objects': 0.32; 'obtain': 0.32; 'programmers': 0.32;
'realize': 0.32; 'received:136': 0.32; 'said,': 0.32; 'split':
0.32; 'but': 0.32; "i'm": 0.33; 'there': 0.33; 'someone': 0.34;
'same': 0.34; 'header:In-Reply-To:1': 0.34; 'definitely': 0.35;
'yes,': 0.35; 'following': 0.35; 'functions': 0.36; 'those': 0.36;
'main': 0.37; "it's": 0.37; 'class': 0.37; 'hard': 0.37; 'once':
0.63; 'skip:m 20': 0.63; 'between': 0.63; 'skip:k 10': 0.64;
'about.': 0.64; 'extend': 0.64; 'imagine': 0.64; 'involve': 0.64;
'your': 0.64; 'similar': 0.65; 'well': 0.65; 'earlier': 0.67;
'lead': 0.67; 'bad': 0.67; 'body': 0.67; 'generally': 0.67;
'further': 0.69; 'varying': 0.69; 'times': 0.69; 'them,': 0.70;
'production': 0.71; 'relevant': 0.73; 'head': 0.73;
'charset:iso-8859-1': 0.73; 'name,': 0.75; 'admit': 0.84; 'be).':
0.84; 'beaten': 0.84; 'choices': 0.84; 'cleaner': 0.84; 'factory':
0.84; 'itself.': 0.84; 'light,': 0.84; 'method,': 0.84;
'minority': 0.84; 'operate.': 0.84; 'readability.': 0.84;
'realise': 0.84; 'say,': 0.84; 'severely': 0.84; 'thus,': 0.84;
'criticism': 0.91; 'soft': 0.93; 'keywords': 0.95
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <CAPTjJmo1MYW4H+fCYfHwLve1tqm3EC0DY6c6M0kQZJhYvpmmwg@mail.gmail.com>
X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com
X-Virus-Scanned: Clear (ClamAV 0.103.5/26542/Sun May 15 10:03:23 2022)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <https://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>
X-Mailman-Original-Message-ID: <YoD+ImdI+VJODwXD@scrozzle>
X-Mailman-Original-References: <t5gdv7$6et$1@dont-email.me>
<671ca838-f59e-4739-f795-4f328399ab9f@DancesWithMice.info>
<YoA8f6siH0NlVXGX@scrozzle>
<aabc28cb-d91c-a855-8d49-257b62e02ffd@DancesWithMice.info>
<CAPTjJmo1MYW4H+fCYfHwLve1tqm3EC0DY6c6M0kQZJhYvpmmwg@mail.gmail.com>
 by: 2QdxY4Rz...@potatochowder.com - Sun, 15 May 2022 13:20 UTC

On 2022-05-15 at 14:44:09 +1000,
Chris Angelico <rosuav@gmail.com> wrote:

> On Sun, 15 May 2022 at 14:27, dn <PythonList@danceswithmice.info> wrote:
> >
> > On 15/05/2022 11.34, 2QdxY4RzWzUUiLuE@potatochowder.com wrote:
> > > On 2022-05-15 at 10:22:15 +1200,
> > > dn <PythonList@DancesWithMice.info> wrote:
> > >
> > >> That said, a function which starts with a list of ifs-buts-and-maybes*
> > >> which are only there to ascertain which set of arguments have been
> > >> provided by the calling-routine; obscures the purpose/responsibility
> > >> of the function and decreases its readability (perhaps not by much,
> > >> but varying by situation).
> > >
> > > Agreed.
> > >
> > >> Accordingly, if the function is actually a method, recommend following
> > >> @Stefan's approach, ie multiple-constructors. Although, this too can
> > >> result in lower readability.
> > >
> > > (Having proposed that approach myself (and having used it over the
> > > decades for functions, methods, procedures, constructors, ...), I also
> > > agree.)
> > >
> > > Assuming good names,¹ how can this lead to lower readability? I guess
> > > if there's too many of them, or programmers have to start wondering
> > > which one to use? Or is this in the same generally obfuscating category
> > > as the ifs-buts-and-maybes at the start of a function?
> > >
> > > ¹ and properly invalidated caches
> >
> > Allow me to extend the term "readability" to include "comprehension".
> > Then add the statistical expectation that a class has only __init__().

Aha. In that light, yeah, in geeral, the more stuff there is, the
harder it is to get your head around it. And even if I document the
class (or the module), no one makes the time to read (let alone
comprehend) the document, which *should* clarify all those things that
are hard to discern from the code itself.

> > Thus, assuming this is the first time (or, ... for a while) that the
> > class is being employed, one has to read much further to realise that
> > there are choices of constructor.
>
> Yeah. I would generally say, though, that any classmethod should be
> looked at as a potential alternate constructor, or at least an
> alternate way to obtain objects (eg preconstructed objects with
> commonly-used configuration - imagine a SecuritySettings class with a
> classmethod to get different defaults).

I think opening up the class and sifting through its classmethods to
find the factory functions is what dn is talking about. Such a design
also means that once I have a SecuritySettings object, its (the
instance's) methods include both instance and class level methods. IMO,
classmethods were/are a bad idea (yes, I'm probably in the minority
around here, but someone has to be). The first person to scream "but
discoverability" will be severely beaten with a soft cushion.

> > Borrowing from the earlier example:
> >
> > > This would be quite pythonic. For example, "datetime.date"
> > > has .fromtimestamp(timestamp), .fromordinal(ordinal),
> > > .fromisoformat(date_string), ...
> >
> > Please remember that this is only relevant if the function is actually a
> > module - which sense does not appear from the OP (IMHO).

Note that datetime.date is a class, not a module.

> > The alternatives' names are well differentiated and (apparently#)
> > appropriately named*.

[...]

> > Continuing the 'have to read further' criticism (above), it could
> > equally-well be applied to my preference for keyword-arguments, in that
> > I've suggested defining four parameters but the user will only call the
> > function with either three or one argument(s). Could this be described
> > as potentially-confusing?

Potentially. :-)

In a well designed *library*, common keywords across multiple functions
provide consistency, which is generally good. Even a bit of redundancy
can be good for the same reason.

OTOH, when there's only one function, and it has a pile of keyword
parameters that can only be used in certain combinations, then it
definitely can be harder to read/understand/use than separate functions
with simpler interfaces.

> Yes, definitely. Personally, I'd split it into two, one that takes the
> existing three arguments (preferably with the same name, for
> compatibility), and one with a different name that takes just the one
> arg. That could be a small wrapper that calls the original, or the
> original could become a wrapper that calls the new one, or the main
> body could be refactored into a helper that they both call. It all
> depends what makes the most sense internally, because that's not part
> of the API at that point.
>
> But it does depend on how the callers operate. Sometimes it's easier
> to have a single function with switchable argument forms, other times
> it's cleaner to separate them.

"Easier" and "cleaner" are very often orthogonal. ;-) (Rich Hickey
(creator of Clojure) talks a lot about the difference between "easy" and
"simple." Arguemnts for and against Unix often involve similar terms.)

And "easier" or "cleaner" for whom? The person writing the function(s),
the person writing code that calls the function(s), the person reading
the function(s), the person reading code that calls the function(s), all
or any of that code? Testers? Maintainers? Their code? Sometimes,
what's easier and cleaner for one is harder and dirtier for another.

As one whose beard likely resembles dn's, I can often spot code written
by developers who have never been involved in testing or maintenance, or
code written by testers who have never written production code (and
don't/won't realize or admit that some tests *are* production code).

Re: Changing calling sequence

<jedcilFhs30U1@mid.individual.net>

 copy mid

https://www.novabbs.com/devel/article-flat.php?id=18281&group=comp.lang.python#18281

 copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ew...@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: Changing calling sequence
Date: Mon, 16 May 2022 10:18:58 +1200
Lines: 13
Message-ID: <jedcilFhs30U1@mid.individual.net>
References: <t5gdv7$6et$1@dont-email.me>
<671ca838-f59e-4739-f795-4f328399ab9f@DancesWithMice.info>
<YoA8f6siH0NlVXGX@scrozzle>
<aabc28cb-d91c-a855-8d49-257b62e02ffd@DancesWithMice.info>
<CAPTjJmo1MYW4H+fCYfHwLve1tqm3EC0DY6c6M0kQZJhYvpmmwg@mail.gmail.com>
<YoD+ImdI+VJODwXD@scrozzle>
<mailman.419.1652620839.20749.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 7H1OHwpKzAthcNXkRiwgGQQK+hGwbD31IYyFFXVN5BIg8USA21
Cancel-Lock: sha1:dogvOoFLVN/n/0oZo3yTe0TBPwY=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0)
Gecko/20100101 Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <mailman.419.1652620839.20749.python-list@python.org>
 by: Greg Ewing - Sun, 15 May 2022 22:18 UTC

On 16/05/22 1:20 am, 2QdxY4RzWzUUiLuE@potatochowder.com wrote:
> IMO,
> classmethods were/are a bad idea (yes, I'm probably in the minority
> around here, but someone has to be).

I don't think class methods are a bad idea per se, but having
them visible through instances seems unnecessary and confusing.
I suspect that wasn't a deliberate design decision, but just a
side effect of using a single class dict for both class and
instance things.

--
Greg

1
server_pubkey.txt

rocksolid light 0.9.7
clearnet tor