[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Paul Sokolovsky
Hello, On Fri, 12 Feb 2021 18:26:53 +1100 Chris Angelico wrote: > On Fri, Feb 12, 2021 at 6:24 PM Paul Sokolovsky > wrote: > > ... And on the 2nd thought, that won't work. The reason it works in > > JS is that it doesn't have tuples. In Python, "(a, b) => (1, 2)" > > means "compare a tuple for

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Random832
On Fri, Feb 12, 2021, at 02:23, Paul Sokolovsky wrote: > > Great to hear there's no desire to stray away from JavaScript just for > > the purpose of being different. > > ... And on the 2nd thought, that won't work. The reason it works in JS > is that it doesn't have tuples. In Python, "(a, b) =>

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Chris Angelico
On Fri, Feb 12, 2021 at 6:24 PM Paul Sokolovsky wrote: > ... And on the 2nd thought, that won't work. The reason it works in JS > is that it doesn't have tuples. In Python, "(a, b) => (1, 2)" means > "compare a tuple for greater-or-equal". Should be safe actually - "=>" is not a valid comparison

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Paul Sokolovsky
Hello, On Fri, 12 Feb 2021 09:55:16 +0300 Paul Sokolovsky wrote: > Hello, > > On Thu, 11 Feb 2021 21:36:25 -0800 > Guido van Rossum wrote: > > > > but I think it'd probably be > > > better to use similar syntax to C#, Java, and Javascript instead, > > > and use () -> [12] or () => 12... > >

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Paul Sokolovsky
Hello, On Thu, 11 Feb 2021 21:36:25 -0800 Guido van Rossum wrote: > > but I think it'd probably be > > better to use similar syntax to C#, Java, and Javascript instead, > > and use () -> [12] or () => 12... > > > > Agreed. I'd prefer the JavaScript solution, since -> already has a >

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Paul Sokolovsky
Hello, On Thu, 11 Feb 2021 23:57:16 -0500 Random832 wrote: [] > > > I'd like to propose the following: > > > > > > w = (): [12] > > > > What will be the meaning of {(): [12]} ? Hint: it will be a > > dictionary of empty tuple mapping to a list, where do you see > > lambda here? > > This

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Guido van Rossum
On Thu, Feb 11, 2021 at 8:58 PM Random832 wrote: > On Thu, Feb 11, 2021, at 06:48, Paul Sokolovsky wrote: > > Hello, > > > > On Thu, 11 Feb 2021 12:24:55 +0100 > > "J. Pic" wrote: > > > > > Hi all, > > > > > > Lambdas can be defined as such: > > > > > > w = lambda: [12] > > > x = lambda y:

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Random832
On Thu, Feb 11, 2021, at 06:48, Paul Sokolovsky wrote: > Hello, > > On Thu, 11 Feb 2021 12:24:55 +0100 > "J. Pic" wrote: > > > Hi all, > > > > Lambdas can be defined as such: > > > > w = lambda: [12] > > x = lambda y: len(y) > > > > I'd like to propose the following: > > > > w = (): [12] >

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Paul Moore
On Thu, 11 Feb 2021 at 15:09, J. Pic wrote: > > I think you also need return, and double space pound space qa to pass linters: > > def foo(): return 1 # noqa > > Instead of > > foo = lambda: 1 > > And this proposal: > > foo(): 1 > > The benefit is just to get more out of the 80 characters when we

[Python-ideas] Re: Gauging appetite for a divergent alternative to pattern matching

2021-02-11 Thread Paul Sokolovsky
Hello, On Fri, 12 Feb 2021 01:37:35 +1100 Steven D'Aprano wrote: > I think it is probably pointless now, but you might get > more response if you post actual examples of the syntax and > semantics, explaining how your proposal differs from the (now > accepted) alternative, and why you

[Python-ideas] Re: Make filter() and map() return function if iterable is not passed

2021-02-11 Thread Chris Angelico
On Fri, Feb 12, 2021 at 1:01 AM Henry Harutyunyan wrote: > this is fine as long as you need to use that filter for once. But if you want > to reuse it you either need to create the iterator every time specifying the > filter function, or save the function in a var and create the filter with >

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread J. Pic
I think you also need return, and double space pound space qa to pass linters: def foo(): return 1 # noqa Instead of foo = lambda: 1 And this proposal: foo(): 1 The benefit is just to get more out of the 80 characters when we want to define a short callback. I understand this is not a life

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Steven D'Aprano
On Thu, Feb 11, 2021 at 12:42:39PM +0100, J. Pic wrote: > foo(x): len(x) > > Would be equivalent to: > > foo = lambda x: len(x) > > Would that work? The question is not whether it would work, but whether it would be a good idea. What benefit does it give? Just write: def foo(x): return

[Python-ideas] Re: Gauging appetite for a divergent alternative to pattern matching

2021-02-11 Thread Steven D'Aprano
I think it is probably pointless now, but you might get more response if you post actual examples of the syntax and semantics, explaining how your proposal differs from the (now accepted) alternative, and why you made the choices you did. You should also consider that pattern matching is built

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-11 Thread Eryk Sun
On 2/11/21, M.-A. Lemburg wrote: > On 11.02.2021 13:49, Eryk Sun wrote: > >> Currently, locale.getpreferredencoding(False) is implemented as >> locale._get_locale_encoding(). This ultimately calls >> _Py_GetLocaleEncoding(), defined in "Python/fileutils.c". >> TextIOWrapper() calls this C

[Python-ideas] Re: Make filter() and map() return function if iterable is not passed

2021-02-11 Thread 永田大和
I think one function returning multiple types must be confusing. You should use `functools.partial` or create new function with def or lambda. >> from functools import partial >> >> pass_filter = partial(filter, lambda x: x > 60) >> foo = [42, 56, 67, 87] >> for i in pass_filter(foo): >>

[Python-ideas] Make filter() and map() return function if iterable is not passed

2021-02-11 Thread Henry Harutyunyan
One of my students gave me an interesting question about why `filter` and `map` do not return a reusable function in case the iterable is not passed. With the current design ``` In [1]: a = filter(lambda x: x > 60) ---

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-11 Thread M.-A. Lemburg
On 11.02.2021 13:49, Eryk Sun wrote: > On 2/11/21, M.-A. Lemburg wrote: > >> I think the main problem here is that open() doesn't use >> locale.getlocale()[1] as default for the encoding parameter, >> but instead locale.getpreferredencoding(False). > > Currently,

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-11 Thread Eryk Sun
On 2/11/21, M.-A. Lemburg wrote: > I think the main problem here is that open() doesn't use > locale.getlocale()[1] as default for the encoding parameter, > but instead locale.getpreferredencoding(False). Currently, locale.getpreferredencoding(False) is implemented as

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread J. Pic
Oh, I didn't think of it, thank you Paul. Inspiration from JavaScript was not a good idea. Instead, would like to propose to make the "def" keyword optional like in bash: foo(x): len(x) Would be equivalent to: foo = lambda x: len(x) Would that work? On Thu, Feb 11, 2021 at 12:24 PM J. Pic

[Python-ideas] Re: Alternate lambda syntax

2021-02-11 Thread Paul Sokolovsky
Hello, On Thu, 11 Feb 2021 12:24:55 +0100 "J. Pic" wrote: > Hi all, > > Lambdas can be defined as such: > > w = lambda: [12] > x = lambda y: len(y) > > I'd like to propose the following: > > w = (): [12] What will be the meaning of {(): [12]} ? Hint: it will be a dictionary of empty tuple

[Python-ideas] Alternate lambda syntax

2021-02-11 Thread J. Pic
Hi all, Lambdas can be defined as such: w = lambda: [12] x = lambda y: len(y) I'd like to propose the following: w = (): [12] x = (y): len(y) Or even another contraction for when there are no arguments: w =: [12] This would also be consistent with the other proposal on anonymous functions

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-11 Thread M.-A. Lemburg
On 10.02.2021 23:10, Eryk Sun wrote: > On 2/10/21, M.-A. Lemburg wrote: >> >> setx PYTHONUTF8 1 >> >> does the trick in an admin command shell on Windows globally. > > The above command sets the variable only for the current user, which > I'd recommend anyway. It does not require administrator

[Python-ideas] Re: Make UTF-8 mode more accessible for Windows users.

2021-02-11 Thread Inada Naoki
I looked some Python courses for children. They won't use venvs. For example, they put .py file in a specified directory, then run it in the Minecraft or other graphical applications. Now I think we should promote putting PYTHONUTF8=1 in user environment before thinking about complex per-site