PyF
PyF copied to clipboard
Document how to use `Show` instance for formatting
One can use :s
to use the Show
instance for formatting, but I don't remember how I found that out, since it isn't documented anywhere as far as I can tell. It would also be nice to use the Show
instance by default (currently, trying to format a custom type gives a big "no instance" error), if that's possible.
Hello @konsumlamm, thank you for this issue.
AFAIK, :s
is implicitly documented by the python documentation (after all, it means "format as string"). But you are right, more documentation would be great. I need to find the time to do that (or find the time to approve super nice MR as you did recently, thank you).
Regarding having Show
by default, I don't really know what to do. PyF uses this complex type class PyFClassify
in order to classify what is the default formatting mode for something. And the error message you got is because there is no PyFClassify
instance for your type, and hence no FormatAny2
(Yes, naming is difficult).
It may be possible to fix that using more overlapping instances, but everytime I tried something with overlapping instances, I ended in an aweful situation.
~~And actually, in python, and maybe that's a good thing, formatting any object with s
fails if the object does not have an __str__
instance. Well, I'm unsure about the correct semantic, but:~~
>>> f"{10:s}"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Unknown format code 's' for object of type 'int'
edit: actually the discussion is about what to do when there is no type specifier, not what to do when the s
is there.
Edit:
Actually, I may be able to do something, at the cost of a code simplification, a little bit less magic and more power.