[Python-ideas] Re: Conditional with statements

2021-02-16 Thread Rob Cliffe via Python-ideas
On 16/02/2021 05:45, Christopher Barker wrote: Still OT ... But I do think you need to consider not just your editor -- if anyone else is going to read your code. They're not (in any universe I can imagine). Exactly -- the most important thing about style is that it be consist

[Python-ideas] Re: Conditional with statements

2021-02-15 Thread Christopher Barker
Still OT ... > But I do think you need to consider not just your editor -- if anyone else > is going to read your code. > > They're not (in any universe I can imagine). > Exactly -- the most important thing about style is that it be consistent within a project's development team -- if that's just

[Python-ideas] Re: Conditional with statements

2021-02-15 Thread Rob Cliffe via Python-ideas
On 15/02/2021 01:58, Christopher Barker wrote: Getting OT here -- you've been warned. On Sun, Feb 14, 2021 at 2:10 AM Rob Cliffe > wrote: You've broken a number of "rules" code code formatting there ;-) Thanks for the quotation marks.  Indeed, PEP

[Python-ideas] Re: Conditional with statements

2021-02-14 Thread David Mertz
On Sun, Feb 14, 2021, 5:46 PM Steven D'Aprano wrote: > I'm curious why you say that if and with are "almost" orthogonal concepts? > They seem completely orthogonal to me. You can mix and match them in > literally every combination: > I mean in a conceptual sense, not as a matter of Python gramma

[Python-ideas] Re: Conditional with statements

2021-02-14 Thread Christopher Barker
Getting OT here -- you've been warned. On Sun, Feb 14, 2021 at 2:10 AM Rob Cliffe wrote: > You've broken a number of "rules" code code formatting there ;-) > > Thanks for the quotation marks. Indeed, PEP 8 provides guidelines, not > diktats. > > A big one is aligning things vertically, which, a

[Python-ideas] Re: Conditional with statements

2021-02-14 Thread Steven D'Aprano
On Mon, Feb 08, 2021 at 02:45:57AM -0500, David Mertz wrote: > I don't like the actual proposal. It weirdly combines almost orthogonal > concepts into the same block statement. I'm curious why you say that if and with are "almost" orthogonal concepts? They seem completely orthogonal to me. You c

[Python-ideas] Re: Conditional with statements

2021-02-14 Thread Rob Cliffe via Python-ideas
On 14/02/2021 02:23, Christopher Barker wrote: Thanks Rob. You've broken a number of "rules" code code formatting there ;-) Thanks for the quotation marks.  Indeed, PEP 8 provides guidelines, not diktats. A big one is aligning things vertically, which, as a rule, I like. but this example doe

[Python-ideas] Re: Conditional with statements

2021-02-13 Thread Christopher Barker
Thanks Rob. You've broken a number of "rules" code code formatting there ;-) A big one is aligning things vertically, which, as a rule, I like. but this example does really push things out away from each other, so I'm not so sure. I found that the original looked like heck when I first opened it

[Python-ideas] Re: Conditional with statements

2021-02-12 Thread Rob Cliffe via Python-ideas
On 08/02/2021 00:39, Brendan Barnwell wrote: On 2021-02-07 09:59, Christopher Barker wrote: All that being said, it's not that big a deal, and I personally don't try to limit to 80 chars per line anyway -- preferring 90 or 95 -- I haven't used a VT100 in decades To be honest I find

[Python-ideas] Re: Conditional with statements

2021-02-09 Thread Jonathan Crall
@Iasizoillo > Only if you don't setup vars like official example* or not calc some statistic after timered block I wrote the official docs, so I'm aware of that case. In the case where setup variables are required it make sense to me to have an extra level of indentation. It just bothers me that

[Python-ideas] Re: Conditional with statements

2021-02-08 Thread Stephen J. Turnbull
Brendan Barnwell writes: > let the editor (as configured by the reader) choose how to map that > [long logical line] onto a visual display. I think your editor must be the first example of true intelligence in a machine. I don't know any editors that reliably do this readably, let alone to my

[Python-ideas] Re: Conditional with statements

2021-02-08 Thread David Mertz
On Mon, Feb 8, 2021, 2:15 AM Brendan Barnwell wrote: > On 2021-02-07 22:36, David Mertz wrote: > > Code is READ far more often than it is written! > > Lines more than 80-ish characters impose a rapidly increasing cognitive > > and visual burden with every additional character. Really, starting at

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread David Mertz
I don't like the actual proposal. It weirdly combines almost orthogonal concepts into the same block statement. Obviously matters other than indent level are important too (notwithstanding my sincere digression into my bête noire). Nested blocks are an excellent way to express roughly orthogonal

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread David Mertz
>From what I can tell, zero-width tabs. Terrible script to write Python in... But fine for the compacted JavaScript sent by most servers. On Mon, Feb 8, 2021, 2:07 AM Chris Angelico wrote: > On Mon, Feb 8, 2021 at 6:04 PM David Mertz wrote: > > > > There's a reason that never in the last 3800 y

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread Christopher Barker
bringing this back (closer to) on lopic: Are you suggesting that we add syntax to Python that makes it easier to keep the number of levels of indentation down? Because when you have a method in a class, you've already lost 1/10 or your line. then you have a for, and an if, and a with, and you've

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread Brendan Barnwell
On 2021-02-07 22:36, David Mertz wrote: Code is READ far more often than it is written! Lines more than 80-ish characters impose a rapidly increasing cognitive and visual burden with every additional character. Really, starting at more like 70 characters. It's not quite exponential in the harm,

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread Chris Angelico
On Mon, Feb 8, 2021 at 6:04 PM David Mertz wrote: > > There's a reason that never in the last 3800 years since Proto-Sinaitic was > the first human script to approximately represent phonemes, has text EVER > been set at more than 80 characters as a widespread convention. > What did they use as

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread David Mertz
There's a reason that never in the last 3800 years since Proto-Sinaitic was the first human script to approximately represent phonemes, has text EVER been set at more than 80 characters as a widespread convention. Large print sizes have existed for a long time, such as newspapers and broadsheets.

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread David Mertz
Code is READ far more often than it is written! Lines more than 80-ish characters impose a rapidly increasing cognitive and visual burden with every additional character. Really, starting at more like 70 characters. It's not quite exponential in the harm, but it's strongly super-linear, after the

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread Stephen J. Turnbull
Oscar Benjamin writes: > On Sun, 7 Feb 2021 at 23:55, Greg Ewing wrote: > > On 8/02/21 6:59 am, Christopher Barker wrote: > > > I find myself > > I often write > My preferred option is There's ALWAYS more than one way to do it! :-) I'm not a fan of the proposed new syntax. A big issue for

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread Brendan Barnwell
On 2021-02-07 09:59, Christopher Barker wrote: All that being said, it's not that big a deal, and I personally don't try to limit to 80 chars per line anyway -- preferring 90 or 95 -- I haven't used a VT100 in decades To be honest I find it kind of ridiculous that people are still worryi

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread Oscar Benjamin
On Sun, 7 Feb 2021 at 23:55, Greg Ewing wrote: > > On 8/02/21 6:59 am, Christopher Barker wrote: > > > I find myself reading entire files into memory and then processing > > them, so as to avoid having to extra-indent all the processing code. > > I don't know why some people seem to be so afraid o

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread Greg Ewing
On 8/02/21 6:59 am, Christopher Barker wrote: I find myself reading entire files into memory and then processing them, so as to avoid having to extra-indent all the processing code. I don't know why some people seem to be so afraid of indentation levels. Remember, you don't *have* to indent

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread Christopher Barker
On Sun, Feb 7, 2021 at 12:37 AM Jonathan Crall wrote: > a with directly after an if costs me 8 spaces instead of 4.\ > Frankly, I think many (most) uses of with are a waste of an indentation level. For example, if all I'm doing is opening a file -- that isn't "logically" a separate block. In fa

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread lasizoillo
El dom, 7 feb 2021 a las 9:38, Jonathan Crall () escribió: > > > Currently my timerit package requires syntax like: > > import timerit > for timer in timerit.Timerit(num=100, bestof=3, verbose=1): > with timer: > [code] > > But that could be simplified to > > > import timerit > for tim

[Python-ideas] Re: Conditional with statements

2021-02-07 Thread Jonathan Crall
@MRAB > It's not that much shorter. You wouldn't be saving much typing or space. IMO, that's a weak point. The amount of indentation you need doubles, and that is significant. Also, common style guides and best practices recommend no more than 80 chars per line. Losing 5.5% of my available space

[Python-ideas] Re: Conditional with statements

2021-02-06 Thread Paul Sokolovsky
Hello, On Sat, 6 Feb 2021 19:57:33 -0500 Jonathan Crall wrote: > I ran into another case where I wish I had some sort of conditional > if. Right, conditional "if" is exactly what we miss in Python. Yes, it's a typo, but it's proverbial Freudian slip, shows what stays behind such proposals - un

[Python-ideas] Re: Conditional with statements

2021-02-06 Thread lasizoillo
El dom, 7 feb 2021 a las 3:08, MRAB () escribió: > On 2021-02-07 00:57, Jonathan Crall wrote: > > > [snip] > > > > To be clear, in the proposed syntax: > > > > if [condition] with [obj]: > > [code] > > > > Would behave exactly as: > > > > if [condition]: > > with [obj]:

[Python-ideas] Re: Conditional with statements

2021-02-06 Thread MRAB
On 2021-02-07 00:57, Jonathan Crall wrote: [snip] To be clear, in the proposed syntax:     if [condition] with [obj]:         [code] Would behave exactly as:     if [condition]:         with [obj]:             [code] Is there any chance that this conditional context manager syntax mi

[Python-ideas] Re: Conditional with statements

2021-02-06 Thread Jonathan Crall
I ran into another case where I wish I had some sort of conditional if. I was writing code to cache autogenerated demodata. import ubelt as ub from os.path import join import json kwargs = {'example': 'config'} dpath = ub.ensure_app_cache_dir('my_modname', 'demodata') fpa

[Python-ideas] Re: Conditional with statements

2020-12-15 Thread Jonathan Crall
Thanks for the link, the rationale for rejection seems reasonable. On Fri, Dec 11, 2020 at 8:19 PM Chris Angelico wrote: > On Sat, Dec 12, 2020 at 11:42 AM Jonathan Crall > wrote: > > > > I'm not sure if this has been asked / suggested before. > > > > I'm wondering if there is any interest in c

[Python-ideas] Re: Conditional with statements

2020-12-12 Thread Steven D'Aprano
On Fri, Dec 11, 2020 at 07:41:27PM -0500, Jonathan Crall wrote: > If `__if__` was defined then > > ``` > with Ctx(): > print('hi') > ``` > > would only print `hi` if `__if__` returned True. This doesn't require a > syntax change. How do you pass arguments to the "if" dunder? A generalised c

[Python-ideas] Re: Conditional with statements

2020-12-11 Thread Chris Angelico
On Sat, Dec 12, 2020 at 11:42 AM Jonathan Crall wrote: > > I'm not sure if this has been asked / suggested before. > > I'm wondering if there is any interest in conditional or loop-based `with` > statements. I think it could be done without a syntax change. > > ### Napkin proposal > > Context man