-
Notifications
You must be signed in to change notification settings - Fork 101
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
Allow using a Parser as a formatter #172
Comments
Similar was suggested in #100 |
I think what I'm suggesting is much simpler. It could hardly be considered new functionality, just exposing existing functionality. Basically what I have in mind is: def format(self, *args, **kwargs) -> str:
return self._format.format(*args, **kwargs) Does this seem reasonable? |
It seems reasonable, one thing does occur to me though that the Parser supports some "extra" types which do not make sense for a formatter, e.g.
So the format method may be more difficult to implement in a full-featured way, rather than just exposing Looking at the
|
Wow, I didn't know about the extra types. I guess |
I think it would nice and elegant if the same object could be used both as a formatter and a parser. This can be achieved by adding a
format
method:Granted, one could simply hold on to the original string and use that, but I think it's useful if we only needed the Parser object for both of these. For example, if you pass the Parser as an argument to a function, currently you need to pass the format string as well, otherwise you have to access the internal
_format
field.At the very least, we should have a
get_format
method to retrieve the internal_format
field.Another reason is that if we are using two different objects for formatting and for parsing, it increases the chance that someone creates a bug by changing one of the objects and forgetting to change the other one.
The text was updated successfully, but these errors were encountered: