Skip to content

Enum for management command verbosity levels #106

@MHLut

Description

@MHLut

Code of Conduct

  • I agree to follow Django's Code of Conduct

Feature Description

Create an (int) enum for verbosity options in Django management commands.

This would be an optional feature for those who prefer a mapped value over a magic number. It would only affect Python code, as an add-on, and would not break existing management calls.

Problem

There is currently no default mapping for verbosity levels: only the numbers 0 to 4 are provided via the default management command option verbosity.

Using numbers directly does not clarify their meaning. They also trigger "magic number" warnings in linters.

Providing a standardized mapping in Django Core would:

  1. More clearly define the meaning of each value.
  2. Make verbosity-based if-statements more descriptive code.
  3. Allow reusability of the values in documentation and tutorials.
  4. Fix magic number warnings in linters and code other quality checkers.
  5. Prevent developers from having to define such an enum themselves in their projects.

Request or proposal

request

Additional Details

Originally posted on the Django Forum: Should management command verbosity levels be labelled?.

Implementation Suggestions

Based on the current levels described in management help commands, the enum could look like this:

from enum import IntEnum


class Verbosity(IntEnum):
    MINIMAL = 0
    NORMAL = 1
    VERBOSE = 2
    VERY_VERBOSE = 3

Names chosen per the help output for the verbosity argument:

-v, --verbosity {0,1,2,3}
    Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Idea refinement - Team creation - For approval

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions