Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short class names #64

Open
jjlee opened this issue Aug 4, 2019 · 0 comments
Open

Short class names #64

jjlee opened this issue Aug 4, 2019 · 0 comments

Comments

@jjlee
Copy link

jjlee commented Aug 4, 2019

  • PrettyPrinter version: 0.18.0
  • Python version: 3.7.3

I see this issue has come up before, in #27, so forgive me if you've already considered this and rejected it.

Description

It would be great if we could write something like:

familiar_classes = [mymodule._longname.SomeClass, mymodule._longname.SomeOtherClass]
prettyprinter.configure(short_names=familiar_classes)

And then instead of class names like the following in the output of prettyprinter.pformat:

mymodule._longname.SomeClass(
    identifier='id-1',
    title='Title',
    other=mymodule._longname.SomeOtherClass(),
    other_class=mymodule._longname.SomeOtherClass,
    something=somemodule.Something(),
    ...

I'd want to see instead:

SomeClass(
    identifier='id-1',
    title='Title',
    other=SomeOtherClass(),
    other_class=SomeOtherClass,
    something=somemodule.Something(),
    ...

Sometimes fully qualified class names (with the module name) get pretty long and obscure the content. In my case, most/all of the classes involved are dataclasses, but from the code it looks like that's not relevant.

I realize you can register your own prettyprinters -- which I've also used for one of my classes -- but for this purpose that seems high-effort and perhaps error-prone. I ended up just editing the source code to never print class names as fully qualified, and that's great for what I'm doing right now.

Even nicer (but likely straying into a separate feature request), I'd love to be able to write something like this and not mutate any global state:

pformat = prettyprinter.make_pretty_printer(include=["dataclasses"], short_names=familiar_classes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant