Author crwilcox
Recipients crwilcox, jitterman, zach.ware
Date 2020-02-10.18:55:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1581360945.24.0.788235115526.issue39601@roundup.psfhosted.org>
In-reply-to
Content
The attached code implements `__format__` on the `Collections` class. In case 1, the template passed to `__format__` is "{v.name}: {v.email}|". In case 2, a name error will occur while processing the f string and v will not be found as no object 'v' exists in locals or globals.

In reviewing PEP 0498, https://www.python.org/dev/peps/pep-0498/, I think the difference is in what object is being formatted.

In case 1 of the attached code, the collection is being formatted. In case 2 where f-strings are used, 'v' is being formatted. Because v doesn't exist in this context, it fails. I found this in the PEP and I think it is what is going on here.

```
Note that __format__() is not called directly on each value. The actual code uses the equivalent of type(value).__format__(value, format_spec), or format(value, format_spec). See the documentation of the builtin format() function for more details.

```
History
Date User Action Args
2020-02-10 18:55:45crwilcoxsetrecipients: + crwilcox, zach.ware, jitterman
2020-02-10 18:55:45crwilcoxsetmessageid: <1581360945.24.0.788235115526.issue39601@roundup.psfhosted.org>
2020-02-10 18:55:45crwilcoxlinkissue39601 messages
2020-02-10 18:55:45crwilcoxcreate