Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#23551 closed Bug (fixed)

Exception raised when using the bash autocompletion with Python 3

Reported by: Marco Buttu Owned by: Marco Buttu
Component: Utilities Version: master
Severity: Normal Keywords:
Cc: marco.buttu@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Marco Buttu)

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

Attachments (2)

subcommand_completed.patch (332 bytes) - added by Marco Buttu 4 years ago.
Patch for the ticket
test_subcommand_completed.patch (2.1 KB) - added by Marco Buttu 4 years ago.
It contains the test and also a patch for the test itself

Download all attachments as: .zip

Change History (8)

comment:1 Changed 4 years ago by Marco Buttu

Cc: marco.buttu@… added
Description: modified (diff)
Owner: changed from nobody to Marco Buttu
Status: newassigned

comment:2 Changed 4 years ago by Tim Graham

Has patch: set
Needs tests: set
Triage Stage: UnreviewedAccepted

Changed 4 years ago by Marco Buttu

Attachment: subcommand_completed.patch added

Patch for the ticket

Changed 4 years ago by Marco Buttu

It contains the test and also a patch for the test itself

comment:3 Changed 4 years ago by Marco Buttu

The test_subcommand_completed.patch contains the regression test and also a patch for the test itself, because in tests/bash_completion/tests.py there was an error in the value assigned to $COMP_CWORD . I created a pull request on github: https://github.com/django/django/pull/3272

comment:4 Changed 4 years ago by Claude Paroz

Needs tests: unset

comment:5 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In e077c29155e5ecb1ff24eb61d30c99505797e84d:

Fixed #23551 -- Fixed bash autocompletion crash on Python 3.

comment:6 Changed 4 years ago by Tim Graham <timograham@…>

In 3a463995433a380c9421eeece90b977e91bacc5b:

Removed incorrect item in 1.7.1 release notes.

The issue only affects master; refs #23551.

Note: See TracTickets for help on using tickets.
Back to Top