[Python-ideas] Re: Make for/while loops nameable.

2020-12-08 Thread Stephen J. Turnbull
Daniel Moisset writes: > For the likely rare situation where I'd want to do this rather than > refactoring into a function, I might try with something like this without > requiring changes to the language: > @contextmanager > def breakable(): Of course this doesn't address Serhiy's case whe

[Python-ideas] Thinking about dead simple import hooks...

2020-12-08 Thread Paul Sokolovsky
Hello, It would be nice to have a simple and easy way to override module importing, instead of that babylon which CPython has in that regard. (Even if initially "limited" to filesystem importing, most people won't ever find that limiting at all.) The desired semantics would be: For "import foo",

[Python-ideas] Re: Thinking about dead simple import hooks...

2020-12-08 Thread Joao S. O. Bueno
And how would Python compute the "full basename of the file to be imported"? How could it guess among all directories on sys.path the one containing the "file", and check if it is a file or a package without going through the existing mechanism? Maybe this proposal is good - but possibly, just cu

[Python-ideas] Re: Thinking about dead simple import hooks...

2020-12-08 Thread Paul Sokolovsky
Hello, On Tue, 8 Dec 2020 07:29:15 -0300 "Joao S. O. Bueno" wrote: > And how would Python compute the "full basename of the file to be > imported"? The way it does it usually. > How could it guess among all directories on sys.path the one > containing the "file", and check if it is a file or a

[Python-ideas] Re: Thinking about dead simple import hooks...

2020-12-08 Thread Chris Angelico
On Tue, Dec 8, 2020 at 9:54 PM Paul Sokolovsky wrote: > > Hello, > > On Tue, 8 Dec 2020 07:29:15 -0300 > "Joao S. O. Bueno" wrote: > > > And how would Python compute the "full basename of the file to be > > imported"? > > The way it does it usually. > That involves a number of searches for exact

[Python-ideas] Lazy Type Casting

2020-12-08 Thread Mathew Elman
I am not sure if this has been suggested before, so my apologies if it has. I would like to propose adding lazy types for casting builtins in a lazy fashion. e.g. `lazy_tuple` which creates a reference to the source iterable and a morally immutable sequence but only populates the tupular contain

[Python-ideas] Re: Thinking about dead simple import hooks...

2020-12-08 Thread Paul Sokolovsky
Hello, On Tue, 8 Dec 2020 22:32:42 +1100 Chris Angelico wrote: > On Tue, Dec 8, 2020 at 9:54 PM Paul Sokolovsky > wrote: > > > > Hello, > > > > On Tue, 8 Dec 2020 07:29:15 -0300 > > "Joao S. O. Bueno" wrote: > > > > > And how would Python compute the "full basename of the file to be > > > im

[Python-ideas] Re: Lazy Type Casting

2020-12-08 Thread Paul Sokolovsky
Hello, On Tue, 08 Dec 2020 11:46:59 - "Mathew Elman" wrote: > I am not sure if this has been suggested before, so my apologies if > it has. > > I would like to propose adding lazy types for casting builtins in a > lazy fashion. e.g. `lazy_tuple` which creates a reference to the > source ite

[Python-ideas] Re: Thinking about dead simple import hooks...

2020-12-08 Thread Chris Angelico
On Tue, Dec 8, 2020 at 11:05 PM Paul Sokolovsky wrote: > > It'd be best to > > just write what you want directly, using the tools in importlib. > > Of course, the implementation of the above for CPython would be based on > importlib. And other implementations could implement that "directly", > for

[Python-ideas] Re: Thinking about dead simple import hooks...

2020-12-08 Thread Paul Sokolovsky
Hello, On Wed, 9 Dec 2020 02:01:58 +1100 Chris Angelico wrote: > On Tue, Dec 8, 2020 at 11:05 PM Paul Sokolovsky > wrote: > > > It'd be best to > > > just write what you want directly, using the tools in importlib. > > > > Of course, the implementation of the above for CPython would be > > ba

[Python-ideas] Re: Make for/while loops nameable.

2020-12-08 Thread Ricky Teachey
On Mon, Dec 7, 2020 at 6:27 PM Daniel Moisset wrote: > For the likely rare situation where I'd want to do this rather than > refactoring into a function, I might try with something like this without > requiring changes to the language: > > from contextlib import contextmanager > > @contextmanager

[Python-ideas] Re: Make for/while loops nameable.

2020-12-08 Thread David Mertz
On Tue, Dec 8, 2020 at 3:31 PM Ricky Teachey wrote: > I agree with the person who called this a brilliant solution. Here is the > code from the link for completeness: > I'm not diss'ing the approach. But it doesn't really save that much over a sentinel variable `break_to_middle`. And if you wa

[Python-ideas] Re: Make for/while loops nameable.

2020-12-08 Thread Ricky Teachey
On Tue, Dec 8, 2020 at 10:42 AM David Mertz wrote: > On Tue, Dec 8, 2020 at 3:31 PM Ricky Teachey wrote: > >> I agree with the person who called this a brilliant solution. Here is the >> code from the link for completeness: >> > > I'm not diss'ing the approach. But it doesn't really save that m

[Python-ideas] __init__ in module names

2020-12-08 Thread Gregory Szorc
PyOxidizer's pure Rust implementation of a meta path importer ( https://pyoxidizer.readthedocs.io/en/stable/oxidized_importer_oxidized_finder.html) has been surprisingly effective at finding corner cases and behavior quirks in Python's importing mechanisms. It was recently brought to my attention

[Python-ideas] Re: __init__ in module names

2020-12-08 Thread M.-A. Lemburg
On 08.12.2020 20:47, Gregory Szorc wrote: > Anyway, I was encouraged by Brett Cannon to email this list to assess the > appetite for introducing a backwards incompatible change to this behavior. So > here's my strawman/hardline proposal: > > 1. 3.10 introduces a DeprecationWarning for "__init__" a

[Python-ideas] Re: __init__ in module names

2020-12-08 Thread Filipe Laíns
On Tue, 2020-12-08 at 11:47 -0800, Gregory Szorc wrote: > PyOxidizer's pure Rust implementation of a meta path importer > (https://pyoxidizer.readthedocs.io/en/stable/oxidized_importer_oxidized_finder.html > ) has been surprisingly effective at finding corner cases and behavior quirks > in Python's

[Python-ideas] Re: __init__ in module names

2020-12-08 Thread Steven D'Aprano
On Tue, Dec 08, 2020 at 08:06:09PM +, Filipe Laíns wrote: > I support this change. Can you explain why you support this breaking change? I am especially interested in cases where people accidentally, or inadvertently, imported "package.__init__" and then used it without realising that it i

[Python-ideas] Re: __init__ in module names

2020-12-08 Thread Steven D'Aprano
On Tue, Dec 08, 2020 at 11:47:22AM -0800, Gregory Szorc wrote: > It was recently brought to my attention via > https://github.com/indygreg/PyOxidizer/issues/317 that "__init__" in module > names is something that exists in Python code in the wild. Can we be clear whether you are talking about "__

[Python-ideas] Re: __init__ in module names

2020-12-08 Thread Gregory Szorc
On Tue, Dec 8, 2020 at 2:44 PM Steven D'Aprano wrote: > On Tue, Dec 08, 2020 at 11:47:22AM -0800, Gregory Szorc wrote: > > > It was recently brought to my attention via > > https://github.com/indygreg/PyOxidizer/issues/317 that "__init__" in > module > > names is something that exists in Python c

[Python-ideas] Re: Lazy Type Casting

2020-12-08 Thread Steven D'Aprano
On Tue, Dec 08, 2020 at 11:46:59AM -, Mathew Elman wrote: > I would like to propose adding lazy types for casting builtins in a > lazy fashion. e.g. `lazy_tuple` which creates a reference to the > source iterable and a morally immutable sequence but only populates > the tupular container wh

[Python-ideas] Re: __init__ in module names

2020-12-08 Thread Steven D'Aprano
On Tue, Dec 08, 2020 at 03:07:48PM -0800, Gregory Szorc wrote: > We're talking about "__init__" being the exact name of a module component. > `"__init__" in fullname.split(".")`, as I wrote in my initial email. I'm sorry, you've just added more confusion to me, rather than less :-( What's a modu

[Python-ideas] An itertools.interleave / itertools.join function

2020-12-08 Thread aurelien . lambert . 89
Hi I like using itertools for creating long strings while not paying the cost of intermediate strings (by eventually calling str.join on the whole iterator). However, one missing feature is to mimic the behavior of str.join as an iterator: an iterator that returns the items of an iterable, separ