Jaymon / pout

Python pretty print on steroids
MIT License
29 stars 0 forks source link

Contrib #53

Closed KOLANICH closed 4 years ago

KOLANICH commented 4 years ago

I'm not sure I want to introduce external dependencies to pout since this is one of my core libraries that gets installed in basically every python environment I work in.

It is in contrib dir. Usually into these dirs content made by third-party devs are placed that is not considered to be part of a main app, but enhance it and are shipped with it. So they are not necessarily must have the same dependencies, they can have own dependencies, but in order to use them the user should install these dependencies. This module is not imported by default, so if you don't use it, you don't have to install RichConsole.

Can you include a description of what this does, maybe including screenshots because it looks like it adds colors to the terminal?

It

Jaymon commented 4 years ago

I'm going to deny this pull request, the point of pout is to debug objects, which is why it is so verbose. If you only want the repr of the objects, just call repr, or you could set POUT_OBJECT_DEPTH=0 I guess if you still want to use pout.

I prefer the verbosity by default with configuration to make it less verbose.

KOLANICH commented 4 years ago

@Jaymon, Are you going to merge 52edeba5315cd57b9353671e8f38c6647d35e762 ? I mean should I send a separate PR with it?

If you only want the repr of the objects, just call repr

In fact initially I wanted to write a lib just printing a repr and a variable name got via reflection and applying heuristics upon source code. But googled a bit and found this lib.

Jaymon commented 4 years ago

In order to merge https://github.com/Jaymon/pout/commit/52edeba5315cd57b9353671e8f38c6647d35e762 I'd love some more reasoning on why the changes were made. What problems did you find with extending pout that prompted the change?

I don't love the existing implementation, but the current approach of just extending pout.value.Inspect to know about a new value or to change how a current value is interpreted and then setting the custom Inspect subclass into pout.value.Value.inspect_class seems to be sufficient for anyone looking to customize the output for those that really need it

KOLANICH commented 4 years ago

and then setting the custom Inspect subclass into pout.value.Value.inspect_class seems to be sufficient for anyone looking to customize the output for those that really need it

It is too much to redefine - everything was hardcoded, even if I replaced 1 class to make it work I had to replace all the classes. These means copypasting the sources. It is easier to rewrite the lib from scratch rather than to do copypastes and then maintain them. So now all the calls are routed through dicts.

Jaymon commented 4 years ago

The documentation on extending pout is not sufficient, you can actually completely replace the current Value system with your own by doing something like:

import pout
from pout.value import Inspect, Value

class MyInspect(Inspect):
    @property
    def classtype(self):
        return MyValue

class MyValue(Value):
    def string_value(self):
        return repr(self.val)

pout.Value.inspect_class = MyInspect

class Foo(object):
    bar = {"che": 1, "baz": 2}

f = Foo()
pout.v(f)

Would result in:

f = <__main__.Foo object at 0x10d025310>

(Untitled 2.py:42)

Likewise, you can selectively override just certain types if you want by doing something like:

# override just dictionary values
class MyInspect(Inspect):
    @property
    def classtype(self):
        if self.is_dict():
            return MyValue
        else:
            return super(MyInspect, self).classtype