On 2022-05-11, David Raymond <david.raym...@tomtom.com> wrote:

> 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")

That would be my preference were I reading the code. It makes it quite
clear that there are two completely separate signatures. I think I
would be a little confused by the 2nd and 3rd values with default
values — the implication would be that I can supply a datetime object
as the first argument and then additional month and date values in the
2nd and 3rd args. You could try to explain it with a comment, but I
tend to ignore comments...
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to