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

break _str_val() into multiple methods #32

Closed
Jaymon opened this issue Sep 6, 2018 · 1 comment
Closed

break _str_val() into multiple methods #32

Jaymon opened this issue Sep 6, 2018 · 1 comment

Comments

@Jaymon
Copy link
Owner

Jaymon commented Sep 6, 2018

so right now _str_val is just a giant if/elif/else, but I would like to change it so it gets the type and then basically takes that type and does:

t = self._get_type(val)
func = getattr(self, "_str_{}".format(t.lower()))
return func(val, depth, **kwargs)

so each of the ifs will be broken into their own method, I think this will help with maintenance.

Each of those methods should take a dict that maps the type to function that will create the string value from that type, so, for example, for module it would be by default:

{
    "MODULE": self._str_val
}

But you could pass in a dict that changes that mapping so you could short circuit the generation and basically say all modules should just render with repr on down the line, the reason for this is to allow properties to be printed on modules, right now I just print the name because pout.v(sys) will choke if it tries to print out the property values, I think there is circular recursion with sys.modules.

@Jaymon
Copy link
Owner Author

Jaymon commented Dec 4, 2018

instead of a function I think maybe it should be a class with a __repr__ method. And all those classes should live in like a value module, and value would have a wrap function, the wrap function would go through all the classes (I guess I would need to set the order?) and pass in the value to be wrapped and then call the is_valid method, which would basically be the statement in the current if/elif block.

pout should also make it easy to wrap something and then turn stuff off, so if I wrapped an instance of my custom class, I could tell the value.InstanceWrapper to not display dicts and things like that so I could more easily customize the output, this would really help sometimes when I dealing with large datasets while trying to figure out how to interact with the 3rd party api.

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