[Python-ideas] Re: Bringing the print statement back

2020-10-20 Thread Rob Cliffe via Python-ideas
No, the proposal was to keep print a function, but to allow alternative syntax without brackets (that would still call it as a function). Best wishes Rob Cliffe On 20/10/2020 05:38, Paul Bryan wrote: printis now a function, and as such can be passed to something that expects a callable. We woul

[Python-ideas] Re: Bringing the print statement back

2020-10-20 Thread J. Pic
Well personally I don't need print at all, I just read code and imagine the output in my head and that's perfectly fine for me (I don't even need a tty). Nonetheless, I believe the majority of Python users are not necessarily familiar with PDB and would be using print as their main debugging tool,

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Rob Cliffe via Python-ideas
-1 on the whole proposal. Currently when I see an f-string such as     f"My name is {name} and my age is {age}." I can easily translate it mentally (if I have to - usually I don't) into     "My name is " + str(name) + " and my age is " + str(age) + "." Whether such a translation is technically ac

[Python-ideas] Re: Bringing the print statement back

2020-10-20 Thread Michael Smith
On Tue, Oct 20, 2020 at 06:02 J. Pic wrote: > Well personally I don't need print at all, I just read code and > imagine the output in my head and that's perfectly fine for me (I > don't even need a tty). > > Nonetheless, I believe the majority of Python users are not > necessarily familiar with P

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Tue, Oct 20, 2020 at 10:37 PM Rob Cliffe via Python-ideas wrote: > In short, "assigning" to f-strings is not and cannot be a simple reversal of > having them in expressions. Rather, it is opening a big can of worms. > It's not a reversal of them being in expressions any more than assigning

[Python-ideas] I frequently find myself in the following situations

2020-10-20 Thread 71f13rvj
Hi Ideas, I frequently find myself in the following situations: 1) I wish to do something if no exception is thrown, for instance: try: logger.debug('Fiber starting: %s', self) try: self._result = self._routine() finally: logger.debug('Fiber fi

[Python-ideas] Re: Bringing the print statement back

2020-10-20 Thread James T Moon
tl;dr *boo* *hiss* I can only imagine the new Python programmer's look of confusion, turning to disgust, turning to giving up. """ Whatever you do, don't write 'print space object', that's old Python 2. ... oh but, except waitasec, but if you're using Python 3.10 or greater then you can use the

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Steven D'Aprano
On Sun, Sep 20, 2020 at 03:59:40AM +0100, Rob Cliffe via Python-ideas wrote: > -1 on the whole proposal. I agree with the negative on this proposal. I don't think that f-strings are a good fit for this, and I'm not sure that we need syntax for something that could be handled by a function almos

[Python-ideas] Optimize out setting unused underscored local variables

2020-10-20 Thread Serhiy Storchaka
It is common to use _ as a placeholder for variable whose value is not used. For example: for _ in range(n) head, _, tail = name.partition(':') first, *_, last = items I though about optimizing out unnecessary assignments. Actually I wrote a patch half year ago and tested it. It did n

[Python-ideas] Re: Bringing the print statement back

2020-10-20 Thread Serhiy Storchaka
20.10.20 12:54, J. Pic пише: > At the same time, Guido says he can remove that cost for no extra > cost, so there's that: how do we find a good reason to not remove a > cost for free ? Sounds like a win/win situation, both for most users > and for the new pegparser. It may have closer to zero cost

[Python-ideas] Re: I frequently find myself in the following situations

2020-10-20 Thread Chris Angelico
On Tue, Oct 20, 2020 at 11:43 PM <71f13...@powerencry.com> wrote: > > Hi Ideas, > > I frequently find myself in the following situations: > > 1) I wish to do something if no exception is thrown, for instance: > > try: > logger.debug('Fiber starting: %s', self) > try: >

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Tue, Oct 20, 2020 at 11:54 PM Steven D'Aprano wrote: > The only advantage, I guess, of f-string like syntax is that the > variable names can be embedded inside the template string: > > f"{path:s} - {errors:d} errors, {%warnings:d}" = line > > but I'm not convinced that's actually an advanta

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 1:13 AM Rob Cliffe wrote: > > On 20/10/2020 13:05, Chris Angelico wrote: > > On Tue, Oct 20, 2020 at 10:37 PM Rob Cliffe via Python-ideas > > wrote: > >> In short, "assigning" to f-strings is not and cannot be a simple reversal > >> of having them in expressions. Rather

[Python-ideas] Re: Bringing the print statement back

2020-10-20 Thread Antal Gábor
Couldn't agree more. On 2020. 10. 20. 16:43, Serhiy Storchaka wrote: 20.10.20 12:54, J. Pic пише: At the same time, Guido says he can remove that cost for no extra cost, so there's that: how do we find a good reason to not remove a cost for free ? Sounds like a win/win situation, both for most

[Python-ideas] Inconsistency in splitting strings

2020-10-20 Thread Antal Gábor
Hey there, This is my first letter here, I'll try my best to explain the problem. First of all, I ran into this "problem" several times. I find str.split() a bit confusing. First of all, this is a corner case, but can happen like every day. print("".split())  # returns [] print("".split(" ")

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 02:18:49AM +1100, Chris Angelico wrote: > > Er, well, why not just add a sscanf to Python? > > A couple of reasons, but the main one is that you can't have "output > variables" (in C, sscanf takes pointers, so you pass it the address of > your variables), which means that

[Python-ideas] Re: Inconsistency in splitting strings

2020-10-20 Thread Eric V. Smith
On 10/20/2020 11:52 AM, Antal Gábor wrote: Hey there, This is my first letter here, I'll try my best to explain the problem. First of all, I ran into this "problem" several times. I find str.split() a bit confusing. First of all, this is a corner case, but can happen like every day. print("

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Paul Moore
On Tue, 20 Oct 2020 at 17:04, Steven D'Aprano wrote: > > In general, Python bindings are *all or nothing* -- either all the > targets get bound, or none of them. I wonder if this could work with the proposed pattern matching statement. The current proposal doesn't allow it, but maybe a future enh

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 3:04 AM Steven D'Aprano wrote: > > That leads to > > an all-or-nothing result for the simple form, and no easy way to do > > anything else. Consider: > > > > a, b, c = sscanf("%d %d %d", "123 432") > > > > Boom! Instead of having a clean way to represent partial parsing. >

[Python-ideas] Re: Optimize out setting unused underscored local variables

2020-10-20 Thread Guido van Rossum
I think it's a micro-optimization that's probably not worth it for most code and more likely to occasionally disappoint people who are using the debugger. Once we have a JIT mode or other super-optimization mode it can be done. On Tue, Oct 20, 2020 at 7:32 AM Serhiy Storchaka wrote: > It is com

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 03:19:20AM +1100, Chris Angelico wrote: > In every sscanf-like system I've used, there is a default value of > some sort, either because variables are automatically initialized, or > because the sscanf construct itself provides a default. Then it won't go "Boom!" as you sa

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 3:46 AM Steven D'Aprano wrote: > > On Wed, Oct 21, 2020 at 03:19:20AM +1100, Chris Angelico wrote: > > > In every sscanf-like system I've used, there is a default value of > > some sort, either because variables are automatically initialized, or > > because the sscanf const

[Python-ideas] Re: Optimize out setting unused underscored local variables

2020-10-20 Thread Steven D'Aprano
On Tue, Oct 20, 2020 at 05:30:54PM +0300, Serhiy Storchaka wrote: > I do not want to create tens of alternate PEPs with minor variations, > and this issue is not worth a PEP. What is your opinion about this? Is > it worth to include such optimization? For what kind of variables should > it be appl

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread David Mertz
On Tue, Oct 20, 2020 at 6:20 PM Chris Angelico wrote: > spam = eggs = cheese = None > f"{spam:d} {eggs:d} {cheese:d}" = "123 456" > Wow! That sure looks like a strong anti-pattern. If some variable was assigned somewhere very distant in the program flow, a parser might succeed where it would ot

[Python-ideas] Upstream Patch to inherit virtual environment ?

2020-10-20 Thread Matthias Bussonnier
Hello Python Ideas, Would there be any interest in upstreaming a patch allowing virtualenv to be inherited in core python ? I'm working with a company that uses such an internal patch and would be ok with me spending some time trying to upstream it. When creating a venv, this let you point

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 5:07 AM David Mertz wrote: > > On Tue, Oct 20, 2020 at 6:20 PM Chris Angelico wrote: >> >> spam = eggs = cheese = None >> f"{spam:d} {eggs:d} {cheese:d}" = "123 456" > > > Wow! That sure looks like a strong anti-pattern. > > If some variable was assigned somewhere very dis

[Python-ideas] Re: Upstream Patch to inherit virtual environment ?

2020-10-20 Thread Wes Turner
> > - are there strange effects e.g. when v1 has pkg.this but v2 has removed > pkg.this and then `impory pkg.this` still succeeds? > parent: pip install pkg==1.0 child: pip install pkg==2.0 child: python -c "import pkg.this" > On Tue, Oct 20, 2020, 2:24 PM Matthias Bussonnier < > bussonniermatth

[Python-ideas] Re: Upstream Patch to inherit virtual environment ?

2020-10-20 Thread Wes Turner
First thoughts: - that's added complexity. - is that reproducible? - how can I detect that that's the case? - a standard way might be easiest - what controls prevent one user from modifying the parent venv and thereby everything that depends upon it? - would there need to be modifications to

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread David Mertz
On Tue, Oct 20, 2020 at 8:41 PM Chris Angelico wrote: > >> f"{spam:d} {eggs:d} {cheese:d}" = "123 456" > > > > Wow! That sure looks like a strong anti-pattern. > > > > If some variable was assigned somewhere very distant in the program > flow, a parser might succeed where it would otherwise fail!

[Python-ideas] Re: Upstream Patch to inherit virtual environment ?

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 5:24 AM Matthias Bussonnier wrote: > > Hello Python Ideas, > > Would there be any interest in upstreaming a patch allowing virtualenv to be > inherited in core python ? > I'm working with a company that uses such an internal patch and would be ok > with me spending some t

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 6:06 AM David Mertz wrote: > > On Tue, Oct 20, 2020 at 8:41 PM Chris Angelico wrote: >> >> >> f"{spam:d} {eggs:d} {cheese:d}" = "123 456" >> > >> > Wow! That sure looks like a strong anti-pattern. >> > >> > If some variable was assigned somewhere very distant in the progra

[Python-ideas] Re: Upstream Patch to inherit virtual environment ?

2020-10-20 Thread Paul Moore
On Tue, 20 Oct 2020 at 20:16, Chris Angelico wrote: > What's the mechanism by which a venv announces its parent, and does > this work correctly if the binary is invoked directly? Currently, if > you invoke /.../.../.../env/bin/python3, it will use the lib directory > from that venv; with this pla

[Python-ideas] Re: Upstream Patch to inherit virtual environment ?

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 6:30 AM Paul Moore wrote: > > On Tue, 20 Oct 2020 at 20:16, Chris Angelico wrote: > > > What's the mechanism by which a venv announces its parent, and does > > this work correctly if the binary is invoked directly? Currently, if > > you invoke /.../.../.../env/bin/python3,

[Python-ideas] Re: Upstream Patch to inherit virtual environment ?

2020-10-20 Thread Matthias Bussonnier
Chris Said: > If I'm understanding you correctly, this means I could do something like: > > $ python3 -m venv env --see-also ../master-env > > and then any packages installed in master-env would be visible inside > this environment too? Seems pretty useful to me. Yes, it does allows multiple p

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 06:17:27AM +1100, Chris Angelico wrote: > No; it can fail if the pattern actually rejects it. For instance, a > pattern of "a{x}b{y}c" can match the string "a" but won't assign to y, It won't assign to x either, if I'm understanding it correctly, since there is nothing fo

[Python-ideas] Re: Optimize out setting unused underscored local variables

2020-10-20 Thread Guido van Rossum
So this would break many uses of locals(). I'm not sure I like that. On Tue, Oct 20, 2020 at 10:16 AM Steven D'Aprano wrote: > On Tue, Oct 20, 2020 at 05:30:54PM +0300, Serhiy Storchaka wrote: > > > I do not want to create tens of alternate PEPs with minor variations, > > and this issue is not w

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 02:15:40AM +1100, Chris Angelico wrote: > On Tue, Oct 20, 2020 at 11:54 PM Steven D'Aprano wrote: > > The only advantage, I guess, of f-string like syntax is that the > > variable names can be embedded inside the template string: > > > > f"{path:s} - {errors:d} errors,

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 10:39 AM Steven D'Aprano wrote: > > The > > f-string has to be a literal - it's not a magic object that you can > > assign to and new locals appear. > > Well, no, it's not an object at all, but surely "you can assign to and > new locals appear" is the whole point of the fea

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 10:22 AM Steven D'Aprano wrote: > > Well... yes. And oddly enough, developing a scanning mini-language > > inspired by the formatting language is *exactly* what this proposal > > is, and has always been. > > That's incorrect. > > The first post in this thread: > > https://m

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread David Mertz
On Wed, Oct 21, 2020 at 1:22 AM Steven D'Aprano wrote: > I think we have at least six mini-languages now? > - regexes > - string interpolation with % > - template strings > - format mini-language > - f-strings > - date/time format strings > We also have the struct mini-language for interpreting

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Eric V. Smith
On 10/20/2020 7:38 PM, Steven D'Aprano wrote: On Wed, Oct 21, 2020 at 02:15:40AM +1100, Chris Angelico wrote: or even: f"{acc},{date},{type},{amount:[0-9.]} {description},{refnum:12s}{reference}" = line At the point you have something that complicated, I think that existing solutions with rege

[Python-ideas] Re: Optimize out setting unused underscored local variables

2020-10-20 Thread Steven D'Aprano
On Tue, Oct 20, 2020 at 04:26:16PM -0700, Guido van Rossum wrote: > So this would break many uses of locals(). I'm not sure I like that. That's a good point I didn't think of. We could rescue the concept by saying that any reference to locals() inside the function disables the elimination, but

[Python-ideas] Re: Optimize out setting unused underscored local variables

2020-10-20 Thread Brandt Bucher
Steven D'Aprano wrote: > We could rescue the concept by saying that any reference to locals() inside > the function disables the elimination, but of course locals can be shadowed > or aliased, and we can't expect the interpreter to do a full analysis of the > entire program. We already do somet

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Steven D'Aprano
On Wed, Oct 21, 2020 at 10:49:41AM +1100, Chris Angelico wrote: > On Wed, Oct 21, 2020 at 10:39 AM Steven D'Aprano wrote: > > > The > > > f-string has to be a literal - it's not a magic object that you can > > > assign to and new locals appear. > > > > Well, no, it's not an object at all, but sure

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 12:08 PM Steven D'Aprano wrote: > > On Wed, Oct 21, 2020 at 10:49:41AM +1100, Chris Angelico wrote: > > On Wed, Oct 21, 2020 at 10:39 AM Steven D'Aprano > > wrote: > > > > The > > > > f-string has to be a literal - it's not a magic object that you can > > > > assign to an

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread David Mertz
On Tue, Oct 20, 2020, 9:17 PM Chris Angelico > Please explain how it's "spooky action at a distance" if it's a > self-contained assignment statement? > I'm not Steven, but I think I'm the first one in the thread to use Einstein's phrase. As I understand your current semantics, that phrase is not

[Python-ideas] Call a function at invocation

2020-10-20 Thread Michael Smith
There are many ways to invoke a function from the commandline. You can use setuptools' console_scripts entrypoint. You can use a decorator from click. And of course you can always do the classic if __name__ == "__main__": main() to call whatever main() is. But there are inconveniences with thes

[Python-ideas] Re: Call a function at invocation

2020-10-20 Thread Guido van Rossum
I think it would be a tad more convincing if there was a way to pass arguments too (even if just a list of strings). At the very least extra arguments should end up in sys.argv[1:]. Then again, presumably the function must be specially crafted for this usage. Why can't you just specially craft a m

[Python-ideas] Re: Optimize out setting unused underscored local variables

2020-10-20 Thread Steve Barnes
Of course there is also the problem of detecting any functions assigned to _ or _T that may be called - otherwise there is a risk of breaking the typical gettext usage in I18n! Steve Barnes Sent from Mail for Windows 10 _

[Python-ideas] Re: Call a function at invocation

2020-10-20 Thread Michael Smith
On Tue, Oct 20, 2020 at 10:19 PM Guido van Rossum wrote: > > I think it would be a tad more convincing if there was a way to pass > arguments too (even if just a list of strings). At the very least extra > arguments should end up in sys.argv[1:]. Could python -m 'module:thunk' have exactly the

[Python-ideas] Re: Call a function at invocation

2020-10-20 Thread Guido van Rossum
On Tue, Oct 20, 2020 at 8:06 PM Michael Smith wrote: > On Tue, Oct 20, 2020 at 10:19 PM Guido van Rossum > wrote: > > > > I think it would be a tad more convincing if there was a way to pass > arguments too (even if just a list of strings). At the very least extra > arguments should end up in sy

[Python-ideas] Re: Call a function at invocation

2020-10-20 Thread Michael Smith
On Tue, Oct 20, 2020 at 23:12 Guido van Rossum wrote: > On Tue, Oct 20, 2020 at 8:06 PM Michael Smith > wrote: > >> On Tue, Oct 20, 2020 at 10:19 PM Guido van Rossum >> wrote: >> > >> > I think it would be a tad more convincing if there was a way to pass >> arguments too (even if just a list of

[Python-ideas] Re: Call a function at invocation

2020-10-20 Thread Guido van Rossum
The ‘if __name__…’ idiom makes one function special. Hm... So if the module has that, will that main() still be called with your proposal? I.e., is __name__ still ‘__main__’? On Tue, Oct 20, 2020 at 20:32 Michael Smith wrote: > > > On Tue, Oct 20, 2020 at 23:12 Guido van Rossum wrote: > >> On T

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread Chris Angelico
On Wed, Oct 21, 2020 at 1:03 PM David Mertz wrote: > > On Tue, Oct 20, 2020, 9:17 PM Chris Angelico >> >> Please explain how it's "spooky action at a distance" if it's a >> self-contained assignment statement? > > > I'm not Steven, but I think I'm the first one in the thread to use Einstein's > p

[Python-ideas] Re: Call a function at invocation

2020-10-20 Thread Michael Smith
On Tue, Oct 20, 2020 at 23:43 Guido van Rossum wrote: > The ‘if __name__…’ idiom makes one function special. Hm... So if the > module has that, will that main() still be called with your proposal? I.e., > is __name__ still ‘__main__’? > Perhaps not. If __name__ were still '__main__' and calling

[Python-ideas] Re: f-strings as assignment targets

2020-10-20 Thread David Mertz
On Wed, Oct 21, 2020, 12:12 AM Chris Angelico > > But I think what you want is for the binding line never to raise, but > also not to have any local means to know whether 'bar' is a name after that > line. Or whether 'foo' is, for that matter. > > Easy: it always is. Whether it has had a value ass

[Python-ideas] Re: Call a function at invocation

2020-10-20 Thread Serhiy Storchaka
21.10.20 05:05, Michael Smith пише: > There are many ways to invoke a function from the commandline. You can > use setuptools' console_scripts entrypoint. You can use a decorator > from click. And of course you can always do the classic > > if __name__ == "__main__": > main() > > to call whatev

[Python-ideas] Re: Optimize out setting unused underscored local variables

2020-10-20 Thread Serhiy Storchaka
20.10.20 19:35, Guido van Rossum пише: > I think it's a micro-optimization that's probably not worth it for most > code and more likely to occasionally disappoint people who are using the > debugger. I thought so too. But these reasons make PEP 640 even more useless. __

[Python-ideas] Re: Optimize out setting unused underscored local variables

2020-10-20 Thread Serhiy Storchaka
20.10.20 20:13, Steven D'Aprano пише: > On Tue, Oct 20, 2020 at 05:30:54PM +0300, Serhiy Storchaka wrote: > >> I do not want to create tens of alternate PEPs with minor variations, >> and this issue is not worth a PEP. What is your opinion about this? Is >> it worth to include such optimization? F

[Python-ideas] Re: Optimize out setting unused underscored local variables

2020-10-20 Thread Serhiy Storchaka
21.10.20 05:23, Steve Barnes пише: > Of course there is also the problem of detecting any functions assigned > to _ or _T that may be called - otherwise there is a risk of breaking > the typical gettext usage in I18n! gettext is usually mapped to global _, so it is not affected. Also, even if eli

[Python-ideas] Re: Call a function at invocation

2020-10-20 Thread Paul Sokolovsky
Hello, On Wed, 21 Oct 2020 00:24:47 -0400 Michael Smith wrote: > On Tue, Oct 20, 2020 at 23:43 Guido van Rossum > wrote: > > > The ‘if __name__…’ idiom makes one function special. Hm... So if the > > module has that, will that main() still be called with your > > proposal? I.e., is __name__ st