Steven D'Aprano <steve+pyt...@pearwood.info> added the comment:

This is not a bug, this is the design of function default arguments.

Default arguments in Python use *early binding*, which means they are 
calculated once, when the function is declared, rather than *late binding*, 
which means they are calculated each time the function is called.

You can get the effect of late binding by testing for None:

    def func(time=None):
        if time is None:
            time = datetime.datetime.today()
        print(time)


Neither choice is right or wrong, they both have advantages and disadvantages. 
Python chooses early binding for function defaults, and late binding for 
closures, which have their own, different, gotchas.

----------
nosy: +steven.daprano
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38451>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to