Skip to content

debug and pprint not working with pydantic classes #54

Closed
@seyhbold

Description

@seyhbold

Hi,

thanks for devtools I use it quite a lot.
Now I stumbled over the following:

>>> from devtools import debug

>>> class W:
...     pass

>>> debug(W)
<stdin>:1 <module> (no code context for debug call, code inspection impossible)
    <class '__main__.W'> (type)

>>> class W(:
...     pass
>>> from pydantic import BaseModel

>>> debug(BaseModel)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/weissl/.pyenv/versions/3.8.2/envs/cauldron/lib/python3.8/site-packages/devtools/debug.py", line 122, in __call__
    s = d_out.str(highlight)
  File "/Users/weissl/.pyenv/versions/3.8.2/envs/cauldron/lib/python3.8/site-packages/devtools/debug.py", line 85, in str
    return prefix + '\n    ' + '\n    '.join(a.str(highlight) for a in self.arguments)
  File "/Users/weissl/.pyenv/versions/3.8.2/envs/cauldron/lib/python3.8/site-packages/devtools/debug.py", line 85, in <genexpr>
    return prefix + '\n    ' + '\n    '.join(a.str(highlight) for a in self.arguments)
  File "/Users/weissl/.pyenv/versions/3.8.2/envs/cauldron/lib/python3.8/site-packages/devtools/debug.py", line 45, in str
    s += pformat(self.value, indent=4, highlight=highlight)
  File "/Users/weissl/.pyenv/versions/3.8.2/envs/cauldron/lib/python3.8/site-packages/devtools/prettier.py", line 80, in __call__
    self._format(value, indent_current=indent, indent_first=indent_first)
  File "/Users/weissl/.pyenv/versions/3.8.2/envs/cauldron/lib/python3.8/site-packages/devtools/prettier.py", line 94, in _format
    gen = pretty_func(fmt=fmt, skip_exc=SkipPretty)
  File "pydantic/utils.py", line 263, in pydantic.utils.Representation.__pretty__
TypeError: __pretty__() takes exactly 2 positional arguments (0 given)

__pretty__() takes exactly 2 positional arguments (0 given)

>>> class W(BaseModel):
...     pass

>>> debug(W)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/weissl/.pyenv/versions/3.8.2/envs/cauldron/lib/python3.8/site-packages/devtools/debug.py", line 122, in __call__
    s = d_out.str(highlight)
  File "/Users/weissl/.pyenv/versions/3.8.2/envs/cauldron/lib/python3.8/site-packages/devtools/debug.py", line 85, in str
    return prefix + '\n    ' + '\n    '.join(a.str(highlight) for a in self.arguments)
  File "/Users/weissl/.pyenv/versions/3.8.2/envs/cauldron/lib/python3.8/site-packages/devtools/debug.py", line 85, in <genexpr>
    return prefix + '\n    ' + '\n    '.join(a.str(highlight) for a in self.arguments)
  File "/Users/weissl/.pyenv/versions/3.8.2/envs/cauldron/lib/python3.8/site-packages/devtools/debug.py", line 45, in str
    s += pformat(self.value, indent=4, highlight=highlight)
  File "/Users/weissl/.pyenv/versions/3.8.2/envs/cauldron/lib/python3.8/site-packages/devtools/prettier.py", line 80, in __call__
    self._format(value, indent_current=indent, indent_first=indent_first)
  File "/Users/weissl/.pyenv/versions/3.8.2/envs/cauldron/lib/python3.8/site-packages/devtools/prettier.py", line 94, in _format
    gen = pretty_func(fmt=fmt, skip_exc=SkipPretty)
  File "pydantic/utils.py", line 263, in pydantic.utils.Representation.__pretty__
TypeError: __pretty__() takes exactly 2 positional arguments (0 given)

__pretty__() takes exactly 2 positional arguments (0 given)

>>>

Could you please give me a hint what I am doing wrong here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions