Akos Kiss <akosthek...@gmail.com> added the comment:
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`. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39694> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com