This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Akos Kiss
Recipients Akos Kiss, ammar2, eric.smith, rhettinger, serhiy.storchaka, vstinner
Date 2020-02-21.12:03:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582286608.63.0.458269464753.issue39694@roundup.psfhosted.org>
In-reply-to
Content
I've come up with some extra examples (use cases?):

```py
import collections

class str2(str):
    def format(self, *args, **kwargs):
        return super().format(*args, **kwargs)

def unpacknonekey(s):
    print('input:', type(s), s)
    try:
        print('str key:', s.format(**{'bar': 'qux'}))
        print('none key:', s.format(**{'bar': 'qux', None: ''}))
    except TypeError as e:
        print('error:', e)

template = 'foo {bar} baz'
unpacknonekey(template)
unpacknonekey(str2(template))
unpacknonekey(collections.UserString(template))
```

The above script gives the following output:

```
input: <class 'str'> foo {bar} baz
str key: foo qux baz
none key: foo qux baz
input: <class '__main__.str2'> foo {bar} baz
str key: foo qux baz
error: format() keywords must be strings
input: <class 'collections.UserString'> foo {bar} baz
str key: foo qux baz
error: format() keywords must be strings
```

This shows inconsistency between `format` of `str` and subclasses of `str` or the standard library's `UserString`.
History
Date User Action Args
2020-02-21 12:03:28Akos Kisssetrecipients: + Akos Kiss, rhettinger, vstinner, eric.smith, serhiy.storchaka, ammar2
2020-02-21 12:03:28Akos Kisssetmessageid: <1582286608.63.0.458269464753.issue39694@roundup.psfhosted.org>
2020-02-21 12:03:28Akos Kisslinkissue39694 messages
2020-02-21 12:03:28Akos Kisscreate