[issue39694] Incorrect dictionary unpacking when calling str.format

2021-12-09 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I disagree, but does not insists if other core developers have other opinion. This is a special case which breaks the rules. The Python language specification does not support non-string keywords. You cannot implement this "feature" in Python. And it is

[issue39694] Incorrect dictionary unpacking when calling str.format

2021-12-08 Thread Eric V. Smith
Eric V. Smith added the comment: I concur with Raymond. -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39694] Incorrect dictionary unpacking when calling str.format

2021-12-08 Thread Raymond Hettinger
Raymond Hettinger added the comment: IMO, there is no actual problem being solved here. Instead there is just a concern that something doesn't feel right. Given that there is no problem in practice, I recommend closing this rather than cluttering docs, tests, or the C code for a

[issue39694] Incorrect dictionary unpacking when calling str.format

2021-12-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: In most cases the test is cheap even for large dict (it has constant complexity if the dict never contained non-string keys). -- ___ Python tracker

[issue39694] Incorrect dictionary unpacking when calling str.format

2021-12-08 Thread Irit Katriel
Irit Katriel added the comment: Reproduced on 3.11. >>> x = {None: ''} >>> ''.format(**x) '' >>> '{x}'.format(**x) Traceback (most recent call last): File "", line 1, in KeyError: 'x' -- components: +Library (Lib) nosy: +iritkatriel versions: +Python 3.11 -Python 3.5, Python 3.6,

[issue39694] Incorrect dictionary unpacking when calling str.format

2020-03-02 Thread STINNER Victor
Change by STINNER Victor : -- nosy: -vstinner ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue39694] Incorrect dictionary unpacking when calling str.format

2020-02-21 Thread Akos Kiss
Akos Kiss 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

[issue39694] Incorrect dictionary unpacking when calling str.format

2020-02-20 Thread Akos Kiss
Akos Kiss added the comment: I couldn't find any discussion in the language reference about fundamental differences between calls to built-in functions and user-defined functions. (I tried to read Sections 6.3.4. "Calls" and 8.6. "Function definitions" carefully.) Until now I had the

[issue39694] Incorrect dictionary unpacking when calling str.format

2020-02-20 Thread Raymond Hettinger
Raymond Hettinger added the comment: I'm with Eric and don't see this as a problem in practice. Also, the kwarg handling for functions is fundamentally different because all arguments need to be matched. In contrast, the kwargs for format() are only used on-demand: >>>

[issue39694] Incorrect dictionary unpacking when calling str.format

2020-02-20 Thread Eric V. Smith
Eric V. Smith added the comment: Okay, then I agree with Serhiy on the change. And I agree that .format(**locals()) is an anti-pattern, and should use .format_map(locals()) instead. Not that it's related directly to this issue, I just like to point it out where I can. --

[issue39694] Incorrect dictionary unpacking when calling str.format

2020-02-20 Thread Akos Kiss
Akos Kiss added the comment: Re: Eric I had a code where `'sometemplate'.format()` got a dictionary from outside (as a parameter, not from `locals()`), and that dictionary had `None` as a key. Actually, I wasn't even aware of that `None` key until I tried to execute the same code in PyPy

[issue39694] Incorrect dictionary unpacking when calling str.format

2020-02-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: See similar issue for SimpleNamespace: https://bugs.python.org/issue31655. We should add a similar check in str.format(). Accepting a non-string keys is an implementation detail. There is no guarantee that it works in other implementations. It should not

[issue39694] Incorrect dictionary unpacking when calling str.format

2020-02-20 Thread Eric V. Smith
Eric V. Smith added the comment: Is this causing some practical problem? I can't think of any way to reference non-string kwargs in a format string, but maybe I'm not being creative enough. And if there is such a way, then changing this wouldn't be backward compatible. --

[issue39694] Incorrect dictionary unpacking when calling str.format

2020-02-20 Thread Ammar Askar
Ammar Askar added the comment: Can re-create, this is because the **kwargs handling inside unicode format only performs a lookup when needed https://github.com/python/cpython/blob/c4cacc8c5eab50db8da3140353596f38a01115ca/Objects/stringlib/unicode_format.h#L393-L424 and doesn't eagerly check

[issue39694] Incorrect dictionary unpacking when calling str.format

2020-02-20 Thread Akos Kiss
New submission from Akos Kiss : My understanding was that in function calls, the keys in an **expression had to be strings. However, str.format seems to deviate from that and allows non-string keys in the mapping (and silently ignores them). Please, see the transcript below: >>> def f():