Jason Spencer <jasonspen...@google.com> added the comment:
Then I would argue that it is at least a documentation bug. The 3.6 format spec mini language still claims that {} is equivalent to {:s}, which now is only conditionally true. I would also argue that having different behavior for {} and {:s}, which are semantically the same in the client's eye, forces the client code to understand more about the object they are stringifying than should be necessary. If one works, so should the other by all descriptions of the format spec. If the format spec is *just* ':s', the library should call the target's __str__ if __format__ is not defined. The library seems willing to do this for the empty format string, but not when the client code specifically asks for a string.... On Sat, Aug 18, 2018 at 10:12 AM Eric V. Smith <rep...@bugs.python.org> wrote: > > Eric V. Smith <e...@trueblade.com> added the comment: > > I agree this is the desired behavior, and not a bug. > > Because you are not specifying a __format__ in your class, > object.__format__ is being called. By design, it does not understand any > formatting specifiers, instead reserving them for your class to implement. > "!s" is the correct way to convert your type to a string. Either that, or > add a __format__ that understands "s". > > Note that not all types understand "s", for example, datetime. > > ---------- > assignee: -> eric.smith > nosy: +eric.smith > stage: -> resolved > status: pending -> closed > > _______________________________________ > Python tracker <rep...@bugs.python.org> > <https://bugs.python.org/issue34425> > _______________________________________ > ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34425> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com