classification
Title: sched.scheduler.enter arguments should not be modifiable
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: giampaolo.rodola, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2012-12-08 10:14 by serhiy.storchaka, last changed 2012-12-29 19:54 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
sched_nonmodifiable_args.patch serhiy.storchaka, 2012-12-08 10:18 review
sched_nonmodifiable_args_2.patch serhiy.storchaka, 2012-12-11 19:45 review
Messages (5)
msg177151 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-08 10:14
Example:

>>> import sched
>>> s=sched.scheduler()
>>> s.enter(10, 1, print)
Event(time=7452.676787873, priority=1, action=<built-in function print>, argument=[], kwargs={})
>>> next(s.queue).argument.append("spam")
>>> s.enter(5, 1, print)
Event(time=7473.326011725, priority=1, action=<built-in function print>, argument=['spam'], kwargs={})
>>> s.run()
spam
spam

Now every s.enter() call (even for other schedulers) without explicit "argument" use ['spam'] as "argument".

Usually functions should not have modifiable arguments (unless it is intentional). We should use non-modifiable value or a sentinel for default. For example an empty tuple as default for "argument" and None as default for "kwargs".
msg177153 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-08 10:18
Sorry, wrong patch.
msg177348 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-11 19:45
Patch updated. Thanks Amaury for nits.
msg178361 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2012-12-28 04:53
Patch looks fine to me.
msg178524 - (view) Author: Roundup Robot (python-dev) Date: 2012-12-29 19:17
New changeset 1c9c0f92df65 by Serhiy Storchaka in branch '3.3':
Issue #16641: Fix default values of sched.scheduler.enter arguments were modifiable.
http://hg.python.org/cpython/rev/1c9c0f92df65

New changeset e22ebc34a8eb by Serhiy Storchaka in branch 'default':
Issue #16641: Fix default values of sched.scheduler.enter arguments were modifiable.
http://hg.python.org/cpython/rev/e22ebc34a8eb
History
Date User Action Args
2012-12-29 19:54:11serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2012-12-29 19:17:06python-devsetnosy: + python-dev
messages: + msg178524
2012-12-28 04:53:49giampaolo.rodolasetmessages: + msg178361
2012-12-27 21:54:30serhiy.storchakasetassignee: serhiy.storchaka
2012-12-11 19:45:58serhiy.storchakasetfiles: + sched_nonmodifiable_args_2.patch

messages: + msg177348
2012-12-08 10:18:59serhiy.storchakasetfiles: + sched_nonmodifiable_args.patch

messages: + msg177153
2012-12-08 10:18:23serhiy.storchakasetfiles: - sched_nonmodifiable_args.patch
2012-12-08 10:15:36serhiy.storchakasettitle: sched.scheduler.enter arguments should be modifiable -> sched.scheduler.enter arguments should not be modifiable
2012-12-08 10:14:21serhiy.storchakacreate