[issue38556] Walrus operator in list comprehensions [Python 3.8.0]
Anselm Kiefner added the comment: I just stumbled over this same restriction and when I googled for "SyntaxError: cannot assign to named expression", 0 actual results showed - an absolute unicorn for a Python error. > "Due to design constraints in the reference implementation (the symbol table > analyser cannot easily detect when names are re-used between the leftmost > comprehension iterable expression and the rest of the comprehension), named > expressions are disallowed entirely as part of comprehension iterable > expressions (the part after each "in", and before any subsequent "if" or > "for" keyword):" Might the new PEG parser maybe help alleviate this restriction, so we could declare this a bug instead? -- nosy: +Anselm Kiefner ___ Python tracker <https://bugs.python.org/issue38556> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30793] Parsing error on f-string-expressions containing strings with backslash
New submission from Anselm Kiefner: Considering that x = 3 f"{'hello' if x == 3 else 'goodbye'} world" is a simple, elegant and powerful piece of code that works just as expected by itself, I often find myself stumbling and wondering why f"text {'\n' if x == 3 else ''} text" fails horribly just because of the \ within the extra quoted string that must be worked around with ugly code like nl = "\n" f"text {nl if x==3 else ''} text" which really doesn't feel like python at all. I am aware that the specification for f-strings says "no \ in expressions", but please consider that in this case, the \ is not really part of the expression but rather part of a string that isn't evaluated as part of the expression, which might just as well be referenced to by a variable. -- messages: 297206 nosy: Anselm Kiefner priority: normal severity: normal status: open title: Parsing error on f-string-expressions containing strings with backslash type: behavior versions: Python 3.7 ___ Python tracker <http://bugs.python.org/issue30793> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30793] Parsing error on f-string-expressions containing strings with backslash
Anselm Kiefner added the comment: Hey Eric, just a heads up. In the latest jupyter notebook, this is valid code: f"{eval('bool(0)\ and True\ ')}" which returns 'False' I don't know how far you want to go, but if someone REALLY wants to use backspace in f-strings just for the sake of it - however ugly it looks like - they already can. -- ___ Python tracker <http://bugs.python.org/issue30793> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue30793] Parsing error on f-string-expressions containing strings with backslash
Anselm Kiefner added the comment: Heh. I had a hunch it could be jupyter specific, but didn't test it. They had problems with f-strings before, it seems they over-fixed those .. Maybe you want to check their implementation and see if it's any good for a general solution? Otherwise I'd volunteer to submit a bug report for their code ;) -- ___ Python tracker <https://bugs.python.org/issue30793> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue27984] singledispatch is wonky with enums
New submission from Anselm Kiefner: from functools import singledispatch from enum import Enum IS = Enum("IS", "a, b") @singledispatch def foo(x): print(foo.dispatch(x)) print("foo") @foo.register(IS.a) def bar(x): print(foo.dispatch(x)) print("bar") @foo.register(int) def baz(x): print("baz") >>> foo(IS.a) foo I think the result is self-explaining. The foo.dispatch() correctly says function bar should be handling the call when IS.a is passed, but foo is handling the call anyway. If an int is passed, baz works as expected. -- messages: 274661 nosy: amogorkon priority: normal severity: normal status: open title: singledispatch is wonky with enums type: behavior versions: Python 3.5 ___ Python tracker <http://bugs.python.org/issue27984> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com