First time here? Check out the FAQ!
1

Wing doesn't print repr of dataclasses in some cases

I've noticed that Wing doesn't print a full repr of some dataclasses in the debug console. For example, a dataclass containing a builtin datetime as one of its fields prints it in its repr, while one using a pendulum.DateTime does not. Is this deliberate? Is there a way to make Wing print all contents, similar to how it would print a namedtuple?

EDIT: I think I was wrong about what triggers this; I'm now able to reproduce it using builtin datetimes, but only if the pprint option is checked in the debug console preferences. I've updated the example below to use datetime.

For example:

from dataclasses import dataclass
import datetime
import typing as tp

@dataclass
class A:
    f: tp.Any = None
    g: tp.Any = None


# Wing shows this as  `A(f=1, g=2)` in the debug console:
A(f=1, g=2)

# Wing shows this as `A()` in the debug console when the pprint option is checked.
A(datetime.datetime.now(), datetime.datetime.now())

Here's a screenshot to prove I'm not crazy: link awaiting moderation

Tmr's avatar
45
Tmr
asked 2025-05-08 15:59:15 -0500, updated 2025-05-09 13:00:48 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

With Python 3.12, the repr() of A(f=pendulum.Date(2025, 1, 1)) is A(f=Date(2025, 1, 1)) -- this is what print(repr(A(f=pendulum.Date(2025, 1, 1))) shows and what the Debug Console displays. Note that the Debug Console simply calls repr() on the value that the input line evaluates to if the pretty print option is off; if the pretty print option is on, the pprint stdlib module is used.

answered 2025-05-08 20:29:22 -0500
This post is a wiki. Anyone with karma >75 is welcome to improve it.
edit flag offensive 0 remove flag delete link

Comments

I'm confused, as my own example now behaves differently than it did yesterday. However, I'm still able to reproduce if I add a second field, if the pprint option is checked. A() is displayed in Wing's terminal, whereas repr() prints A(f=..., g=...). I will edit the code in my question rather than trying to post it in a comment. Are you able to reproduce the behavior I see?

Tmr's avatar Tmr (2025-05-09 13:00:50 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer