Message362404
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`. |
|
Date |
User |
Action |
Args |
2020-02-21 12:03:28 | Akos Kiss | set | recipients:
+ Akos Kiss, rhettinger, vstinner, eric.smith, serhiy.storchaka, ammar2 |
2020-02-21 12:03:28 | Akos Kiss | set | messageid: <1582286608.63.0.458269464753.issue39694@roundup.psfhosted.org> |
2020-02-21 12:03:28 | Akos Kiss | link | issue39694 messages |
2020-02-21 12:03:28 | Akos Kiss | create | |
|