#23551: Exception raised when using the bash autocompletion with Python 3
-----------------------------+---------------------------------------
Reporter: marco-buttu | Owner: marco-buttu
Type: Bug | Status: assigned
Component: Utilities | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+---------------------------------------
Changes (by marco-buttu):
* status: new => assigned
* cc: marco.buttu@… (added)
* needs_better_patch: => 0
* needs_tests: => 0
* owner: nobody => marco-buttu
* needs_docs: => 0
Old description:
> My environment is Python 3.4 and Linux Mint 17. When using the django
> autocompletion, a TAB-completion after a command gives me an exception.
> For instance, typing a TAB after *django-admin startproject*:
>
> {{{
> $ django-admin startproject Traceback (most recent call last):
> ...
> File ".../django/core/management/__init__.py", line 262, in
> autocomplete
> options = sorted((k, v) for k, v in options if k.startswith(curr))
> TypeError: unorderable types: bool() < NoneType()
> }}}
>
> That happens because at line 225 the *options* list is initilized as:
>
> {{{
> options = [('--help', None)]
> }}}
>
> and at line 263:
>
> {{{
> options = sorted((k, v) for k, v in options if k.startswith(curr))
> }}}
>
> But since *options* contains *--help* twice, in Python 3 we get an error
> comparing a *bool* with *None*:
>
> {{{
> >>> sorted([('foo', True), ('--help', False), ('--help', None)])
> Traceback (most recent call last):
> ...
> TypeError: unorderable types: NoneType() < bool()
> }}}
>
> That obviously does not happen in Python 2. The doctring of
> *autocomplete()* says:
>
> {{{
> >>> from django.core.management import ManagementUtility
> >>> for line in
> ManagementUtility.autocomplete.__doc__.splitlines()[10:15]:
> ... print(line)
> ...
>
> Subcommand options are saved as pairs. A pair consists of
> the long option string (e.g. '--exclude') and a boolean
> value indicating if the option requires arguments. When
> printing to
> stdout, an equal sign is appended to options which require
> arguments.
> }}}
>
> So, how come *options* is initialized with the pair *('--help', None)*
> instead of *('--help', False)*?
New description:
My environment is Python 3.4 and Linux Mint 17. When using the django
autocompletion, a TAB-completion after a command gives me an exception.
For instance, typing a TAB after `django-admin startproject`:
{{{
$ django-admin startproject Traceback (most recent call last):
...
File ".../django/core/management/__init__.py", line 262, in autocomplete
options = sorted((k, v) for k, v in options if k.startswith(curr))
TypeError: unorderable types: bool() < NoneType()
}}}
That happens because at line 225 the `options` list is initilized as:
{{{
options = [('--help', None)]
}}}
and at line 263:
{{{
options = sorted((k, v) for k, v in options if k.startswith(curr))
}}}
But since `options` contains `--help` twice, in Python 3 we get an error
comparing a `bool` with `None`:
{{{
>>> sorted([('foo', True), ('--help', False), ('--help', None)])
Traceback (most recent call last):
...
TypeError: unorderable types: NoneType() < bool()
}}}
That obviously does not happen in Python 2. The doctring of
`autocomplete()` says:
{{{
>>> from django.core.management import ManagementUtility
>>> for line in
ManagementUtility.autocomplete.__doc__.splitlines()[10:15]:
... print(line)
...
Subcommand options are saved as pairs. A pair consists of
the long option string (e.g. '--exclude') and a boolean
value indicating if the option requires arguments. When
printing to
stdout, an equal sign is appended to options which require
arguments.
}}}
So, how come `options` is initialized with the pair `('--help', None)`
instead of `('--help', False)`?
--
--
Ticket URL: <https://code.djangoproject.com/ticket/23551#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/069.5dc3614c95a6a19f65f6eacfad4aeb98%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.