tommikaikkonen / prettyprinter

Syntax-highlighting, declarative and composable pretty printer for Python 3.5+
https://prettyprinter.readthedocs.io
MIT License
336 stars 20 forks source link

Django 2.x models with choices cause exceptions #76

Open dragonpaw opened 4 years ago

dragonpaw commented 4 years ago

Description

Attempting to print a simple database object with choices on one field.

class User(models.Model):
    A = 'a'
    B = 'b'
    C = 'c'

    role = models.CharField(
        choices=(
            (A, "Alpha"),
            (B, "Beta"),
            (C, "Charlie"),
        ),
        default=A,
        max_length=20,
    )

Stack trace

Traceback (most recent call last):
  File "/Users/ash/src/xxx/.venv/lib/python3.7/site-packages/prettyprinter/prettyprinter.py", line 387, in _run_pretty
    doc = pretty_fn(value, ctx)
  File "/Users/ash/src/xxx/.venv/lib/python3.7/site-packages/prettyprinter/extras/django.py", line 169, in pretty_base_model
    display
  File "/Users/ash/src/xxx/.venv/lib/python3.7/site-packages/prettyprinter/prettyprinter.py", line 154, in comment_doc
    return annotate(CommentAnnotation(comment_text), doc)
  File "/Users/ash/src/xxx/.venv/lib/python3.7/site-packages/prettyprinter/prettyprinter.py", line 111, in __init__
    assert isinstance(value, str)
AssertionError