[issue9379] random.randrange behaviour problems

Łukasz Langa report at bugs.python.org
Sun Jul 25 23:31:04 CEST 2010


Łukasz Langa <lukasz at langa.pl> added the comment:

My suggestions on how the patches should work always assumed that we want 100% backward compatibility and there might exist some crazy code that is actually using positional/keyword argument mixing. If that is no problem for us then I'm all in favor of removing the posibility to mix positional with keyword args in this case.

1B is meant to solve the help() issue. The basic idea is to change the definition so that help() shows a sensible default for all cases. The current one when `start` becomes `stop` is not. The new definition would be:

  def randrange(self, limit, *args, **kwargs)

The docstring would need to have an explanation on the role of `limit` in each sensible case.

Then in the function body there would be some basic code going through what was specified by the user in the args, to assign these values to variables for existing implementation (which is OK).

In effect, there would be 3 major advantages:
- this is backward compatible
- help() would not confuse users
- invocations like randrange(start=30) or randrange(stop=10, step=8) would work properly

If you don't strongly disagree then maybe it will be simpler to just provide a patch for you to review :)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9379>
_______________________________________


More information about the Python-bugs-list mailing list