Re: [Python-ideas] Generator-based context managers can't skip __exit__

2016-11-06 Thread Ram Rachum
wrote: > On 6 November 2016 at 14:46, Ram Rachum <r...@rachum.com> wrote: > > I worked around this problem by adding `except GeneratorExit: raise` in > my > > context manager, but that's an ugly solution. > > Adding `except GeneratorExit: raise` to a try statement w

Re: [Python-ideas] Generator-based context managers can't skip __exit__

2016-11-06 Thread Ram Rachum
On Sun, Nov 6, 2016 at 9:38 AM, Nick Coghlan <ncogh...@gmail.com> wrote: > On 6 November 2016 at 17:18, Ram Rachum <r...@rachum.com> wrote: > > On Sun, Nov 6, 2016 at 8:53 AM, Nick Coghlan <ncogh...@gmail.com> wrote: > >> There's still something ser

Re: [Python-ideas] Generator-based context managers can't skip __exit__

2016-11-06 Thread Ram Rachum
for every generator-based context manager that I create, so it's not as bad as the previous workaround in my opinion. (I wouldn't create a new attribute for each context manager, but just have a list with a mangled name on `sys` that'll hold all of them.) On Sun, Nov 6, 2016 at 8:02 AM, Ram Rachum

Re: [Python-ideas] Generator-based context managers can't skip __exit__

2016-11-06 Thread Ram Rachum
On Sun, Nov 6, 2016 at 8:53 AM, Nick Coghlan <ncogh...@gmail.com> wrote: > On 6 November 2016 at 16:07, Ram Rachum <r...@rachum.com> wrote: > > Heh, I just played with this, and found a workaround. If I do something > like > > this after creating th

Re: [Python-ideas] Generator-based context managers can't skip __exit__

2016-11-18 Thread Ram Rachum
Sure, here are a couple of use cases: 1. I'm making a program that lets people lease machines. They can issue a command to lease 7 machines. When they do, my program leases them one by one and adds them all to an exit stack, so in case there aren't 7 machines available, all the machines we leased

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Ram Rachum
Another idea: Maybe make json.load and json.dump support Path objects? On Mon, Mar 27, 2017 at 4:36 PM, Paul Moore wrote: > On 27 March 2017 at 15:33, Donald Stufft wrote: > > What do you think about adding methods pathlib.Path.write_json and > >

Re: [Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Ram Rachum
Oh, and also it saves you from having to import json. On Mon, Mar 27, 2017 at 2:50 PM, Ram Rachum <r...@rachum.com> wrote: > Hi guys, > > What do you think about adding methods pathlib.Path.write_json and > pathlib.Path.read_json , similar to write_text, write_bytes, read_

[Python-ideas] Add pathlib.Path.write_json and pathlib.Path.read_json

2017-03-27 Thread Ram Rachum
Hi guys, What do you think about adding methods pathlib.Path.write_json and pathlib.Path.read_json , similar to write_text, write_bytes, read_text, read_bytes? This would make writing / reading JSON to a file a one liner instead of a two-line with clause. Thanks, Ram.

[Python-ideas] Introduce BaseTimeoutError

2017-04-01 Thread Ram Rachum
Today I got burned because I had code that did this: except TimeoutError: When it should have done this: except socket.timeout: There's also another timeout error class in asyncio. Initially I thought, why not make them all use the same exception class? But Guido objects to that: I

Re: [Python-ideas] Suggestion: Add shutil.get_dir_size

2017-05-03 Thread Ram Rachum
Calling `du` is possible but I prefer to avoid these kinds of solutions. (OS-specific, parsing text output from a third-party program.) On Wed, May 3, 2017 at 1:57 AM, Cameron Simpson <c...@zip.com.au> wrote: > On 02May2017 22:07, Ram Rachum <r...@rachum.com> wrote: > >>

[Python-ideas] Suggestion: Add shutil.get_dir_size

2017-05-02 Thread Ram Rachum
Hi, I have a suggestion: Add a function shutil.get_dir_size that gets the size of a directory, including all the items inside it recursively. I currently need this functionality and it looks like I'll have to write my own function for it. Cheers, Ram.

Re: [Python-ideas] Support parsing stream with `re`

2018-10-08 Thread Ram Rachum
on this computer, and Process Explorer says it's almost full, just ~150MB left. This is physical memory. To your question: The loop does iterate, i.e. finding multiple matches. On Mon, Oct 8, 2018 at 1:20 PM Cameron Simpson wrote: > On 08Oct2018 10:56, Ram Rachum wrote: > >That's i

Re: [Python-ideas] Support parsing stream with `re`

2018-10-08 Thread Ram Rachum
at 7:49 PM <2...@jmunch.dk> wrote: > On 18-10-07 16.15, Ram Rachum wrote: > > I tested it now and indeed bytes patterns work on memoryview objects. > > But how do I use this to scan for patterns through a stream without > > loading it to memory? > > An mmap ob

Re: [Python-ideas] Support parsing stream with `re`

2018-10-08 Thread Ram Rachum
ich command do I run on Linux to verify that the process isn't taking too much RAM? Thanks, Ram. On Mon, Oct 8, 2018 at 3:02 PM Erik Bray wrote: > On Mon, Oct 8, 2018 at 12:20 PM Cameron Simpson wrote: > > > > On 08Oct2018 10:56, Ram Rachum wrote: > > >That's incredi

Re: [Python-ideas] Support parsing stream with `re`

2018-10-08 Thread Ram Rachum
Thanks for your help everybody! I'm very happy to have learned about mmap. On Mon, Oct 8, 2018 at 3:27 PM Richard Damon wrote: > On 10/8/18 8:11 AM, Ram Rachum wrote: > > " Windows will aggressively fill up your RAM in cases like this > > because after all why not? Ther

Re: [Python-ideas] Support parsing stream with `re`

2018-10-06 Thread Ram Rachum
10:22, Ram Rachum пише: > > I'd like to use the re module to parse a long text file, 1GB in size. I > > wish that the re module could parse a stream, so I wouldn't have to load > > the whole thing into memory. I'd like to iterate over matches from the > > stream with

Re: [Python-ideas] Support parsing stream with `re`

2018-10-06 Thread Ram Rachum
"This is a regular expression problem, rather than a Python problem." Do you have evidence for this assertion, except that other regex implementations have this limitation? Is there a regex specification somewhere that specifies that streams aren't supported? Is there a fundamental reason that

[Python-ideas] Support parsing stream with `re`

2018-10-06 Thread Ram Rachum
Hi, I'd like to use the re module to parse a long text file, 1GB in size. I wish that the re module could parse a stream, so I wouldn't have to load the whole thing into memory. I'd like to iterate over matches from the stream without keeping the old matches and input in RAM. What do you think?

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Ram Rachum
basically a poor man's regex engine. I'm more likely to use a shim to make the re package work on streams (like regexy or reading chunks until I get a match) than to use an algorithm like that. Thanks, Ram. On Sun, Oct 7, 2018 at 9:58 AM Cameron Simpson wrote: > On 07Oct2018 07:30, Ram Rac

Re: [Python-ideas] Support parsing stream with `re`

2018-10-07 Thread Ram Rachum
I tested it now and indeed bytes patterns work on memoryview objects. But how do I use this to scan for patterns through a stream without loading it to memory? On Sun, Oct 7, 2018 at 4:24 PM <2...@jmunch.dk> wrote: > On 18-10-07 15.11, Ram Rachum wrote: > > > Unfortunately, i

Re: [Python-ideas] Support parsing stream with `re`

2018-10-06 Thread Ram Rachum
On Sun, Oct 7, 2018 at 4:40 AM Steven D'Aprano wrote: > I'm sure that Python will never be as efficient as C in that regard > (although PyPy might argue the point) but is there something we can do > to ameliorate this? If we could make char-by-char processing only 10 > times less efficient than

Re: [Python-ideas] Support parsing stream with `re`

2018-10-06 Thread Ram Rachum
tentially thousands of lines. Then I'll know just where to put my M600 and how much retraction to do afterwards. Thanks, Ram. On Sat, Oct 6, 2018 at 6:58 PM Ned Batchelder wrote: > On 10/6/18 7:25 AM, Ram Rachum wrote: > > "This is a regular expression problem, rather than a Python

Re: [Python-ideas] Idea: Allow multiple levels of tracers

2019-04-28 Thread Ram Rachum
won't have high confidence that the mock is reliable. On Sun, Apr 28, 2019, 11:06 Barry Scott wrote: > > > On 25 Apr 2019, at 15:51, Ram Rachum wrote: > > Hi, > > Here's something I want in Python: Multiple levels of tracers working on > top of each other, instead of just on

[Python-ideas] Idea: Allow multiple levels of tracers

2019-04-25 Thread Ram Rachum
Hi, Here's something I want in Python: Multiple levels of tracers working on top of each other, instead of just one. I'm talking about the tracer that one can set by calling sys.settrace. I've recently released PySnooper: https://github.com/cool-RR/PySnooper/ One of the difficulties I have, is

Re: [Python-ideas] Idea: Allow multiple levels of tracers

2019-04-25 Thread Ram Rachum
Oh wow, I didn't even consider that. I think you're right, I'll do more thinking about this. Thanks Anders! On Thu, Apr 25, 2019 at 6:10 PM Anders Hovmöller wrote: > Can't this be implemented today by a simple monkey patch of sys.settrace? > > On 25 Apr 2019, at 16:51, Ram Rachum wrot

Re: [Python-ideas] Idea: Allow multiple levels of tracers

2019-04-25 Thread Ram Rachum
ied by "simple(!) monkeypatch of > sys.settrace", but the trickiest part of Ram's proposal is that the body of > one trace function would still trigger the remaining trace functions. That > to me sounds like it's going to require changes to ceval.c > > --Ned. > On 4/2

Re: [Python-ideas] Idea: Allow multiple levels of tracers

2019-04-25 Thread Ram Rachum
:16 PM Ram Rachum wrote: > Oh wow, I didn't even consider that. I think you're right, I'll do more > thinking about this. Thanks Anders! > > On Thu, Apr 25, 2019 at 6:10 PM Anders Hovmöller > wrote: > >> Can't this be implemented today by a simple monkey patch of sys.s

Re: [Python-ideas] Idea: Allow multiple levels of tracers

2019-04-25 Thread Ram Rachum
that the body of > one trace function would still trigger the remaining trace functions. That > to me sounds like it's going to require changes to ceval.c > > --Ned. > On 4/25/19 12:26 PM, Ram Rachum wrote: > > Hmm, looks like, for this to work, you'll need the existing

[Python-ideas] `raise as` to raise with current exception as cause

2020-02-07 Thread Ram Rachum
Hi, I'd like to suggest an idea, that builds on PEPs 3134 and 409. This idea came up when discussing a problem on the django-developers mailing list: https://groups.google.com/forum/?utm_medium=email_source=footer#!msg/django-developers/ibEOt3A9c2M/EP4gbQyTFwAJ I'll first explain my idea, and

[Python-ideas] Re: `raise as` to raise with current exception as cause

2020-02-07 Thread Ram Rachum
On Fri, Feb 7, 2020 at 7:47 PM Shai Berger wrote: > Hi, > > In the Django thread, I suggested that an implicit "raise from" should > be the behavior whenever an exception is raised directly in > exception-handling code (that is, within an except: or finally: > clause). Ram claimed there were

[Python-ideas] Re: `raise as` to raise with current exception as cause

2020-02-07 Thread Ram Rachum
Hi Soni, I think that your suggestion is identical to Shai's. It would be good, but unfortunately it has the 3 problems I raised in my email from an hour ago. On Fri, Feb 7, 2020 at 11:00 PM Soni L. wrote: > > > On 2020-02-07 5:38 p.m., Ram Rachum wrote: > > I would like

[Python-ideas] Re: `raise as` to raise with current exception as cause

2020-02-07 Thread Ram Rachum
I would like to raise a sort-of ultimatum to everyone in this thread. As far as I know, the `raise foo from bar` syntax, and the distinction between the two exception-chaining messages, didn't really catch on. I know about them, like them and use them, but most Python developers and open-source

[Python-ideas] Re: `raise as` to raise with current exception as cause

2020-02-08 Thread Ram Rachum
On Sat, Feb 8, 2020 at 12:27 PM Paul Moore wrote: > > So I'd be hesitant about calling exception chaining a failure (like > the OP, not Steven, did) for a while yet. And even then, I would't > call it a failure, just a relatively niche feature that is helpful in > some uncommon cases. > I

[Python-ideas] zip(x, y, z, strict=True)

2020-04-20 Thread Ram Rachum
Here's something that would have saved me some debugging yesterday: >>> zipped = zip(x, y, z, strict=True) I suggest that `strict=True` would ensure that all the iterables have been exhausted, raising an exception otherwise. This is useful in cases where you're assuming that the iterables

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-20 Thread Ram Rachum
this, with the existing zip logic. On Mon, Apr 20, 2020, 23:34 Andrew Barnert wrote: > On Apr 20, 2020, at 10:42, Ram Rachum wrote: > > > > Here's something that would have saved me some debugging yesterday: > > > > >>> zipped = zip(x, y, z, strict=True) > > >

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-21 Thread Ram Rachum
On Tue, Apr 21, 2020 at 11:36 AM Serhiy Storchaka wrote: > 20.04.20 23:33, Andrew Barnert via Python-ideas пише: > > Should this print 1 or 2 or raise StopIteration or be a don’t-care? > > > > Should it matter if you zip(y, x, strict=True) instead? > > It should print 2 in both cases. The only

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Ram Rachum
Thanks everybody for your answers, and especially Ricky for finding this note. On Wed, Apr 29, 2020 at 2:20 PM Ricky Teachey wrote: > I was playing around with deque today, and there were a couple of >> operations I wanted to do, that can't really be done efficiently with deque >> because of

[Python-ideas] Introduce 100 more built-in exceptions

2020-05-01 Thread Ram Rachum
Hi, Here's something I wanted in Python for many years. If this has been discussed in the past, please refer me to that discussion. On one hand, it's something that I can't imagine the python-dev community supporting. On the other hand, it would maintain backward compatibility. I wish there

[Python-ideas] Re: Introduce 100 more built-in exceptions

2020-05-01 Thread Ram Rachum
On Fri, May 1, 2020 at 12:28 PM Steven D'Aprano wrote: > Is "100 more exceptions" hyperbole? Or do you actually mean precisely > one hundred more exceptions? > It is hyperbole. I should have realized that the way I phrased it was provocative. Maybe people would have responded better if I put

[Python-ideas] Re: Introduce 100 more built-in exceptions

2020-05-01 Thread Ram Rachum
On Fri, May 1, 2020 at 10:28 AM Serhiy Storchaka wrote: > Could you please provide a list of these 100 exceptions? If you create a > PR, with documentation and tests, it would be a good start of the > discussion. > That's not a reasonable request. If there's enough support for this idea, then

[Python-ideas] Re: Introduce 100 more built-in exceptions

2020-05-01 Thread Ram Rachum
On Fri, May 1, 2020 at 11:37 AM M.-A. Lemburg wrote: > Hi Ram, > > I think you are confusing the exception type with the exception > reason. Some time ago `ModuleNotFoundError` was added as a subclass of `ImportError`, which I really liked. Was this also another instance of a confusion between

[Python-ideas] Re: Introduce 100 more built-in exceptions

2020-05-01 Thread Ram Rachum
`, then I know exactly what it is they're catching. On Fri, May 1, 2020 at 9:48 AM Ram Rachum wrote: > Hi, > > Here's something I wanted in Python for many years. If this has been > discussed in the past, please refer me to that discussion. > > On one hand, it's something th

[Python-ideas] Re: PEP 618: Add Optional Length-Checking To zip

2020-05-02 Thread Ram Rachum
I'm +1 obviously :) On Fri, May 1, 2020 at 9:19 PM Brandt Bucher wrote: > I have pushed a first draft of PEP 618: > > https://www.python.org/dev/peps/pep-0618 > > Please let me know what you think – I'd love to hear any *new* feedback > that hasn't yet been addressed in the PEP! > > Brandt >

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-05-02 Thread Ram Rachum
That was a good email Alex. Besides the relevant examples, you've put into words things that I wanted to say but didn't realize it. Good job :) On Sat, May 2, 2020 at 4:00 PM Alex Hall wrote: > On Sat, May 2, 2020 at 1:19 PM Steven D'Aprano > wrote: > >> On Sat, May 02, 2020 at 09:54:46AM

[Python-ideas] Re: zip(x, y, z, strict=True)

2020-04-26 Thread Ram Rachum
Here's an idea for combining zip_longest with zip strict. Define zip like so: def zip(*iterables, strict=False, fill=object()) With no arguments, it's the regular old zip. With `strict=True`, it ensures the iterators are equal. If you pass in an argument for `fill`, it becomes zip_longest. On

[Python-ideas] Re: deque: Allow efficient operations

2020-04-29 Thread Ram Rachum
On Wed, Apr 29, 2020 at 1:54 PM Paul Sokolovsky wrote: > If you want a different data structure, [...] implement such a > data structure > And if I wanted an answer like "it's the way that it is because it's the way that it is" I wouldn't be posting on python-ideas. Is there a strategic

[Python-ideas] deque: Allow efficient operations

2020-04-29 Thread Ram Rachum
I was playing around with deque today, and there were a couple of operations I wanted to do, that can't really be done efficiently with deque because of its implementation. I was iterating through items of a deque, and in some cases I wanted to delete an item that I've found. As far as I

[Python-ideas] Re: Adding slice Iterator to Sequences (was: islice with actual slices)

2020-05-09 Thread Ram Rachum
nished, and was > waiting 'till I had time to deal with the discussion. > > But since it was brought up -- here we go! > > If folks have an interest in this, I'd love to get feedback. > > -CHB > > > > > On Sat, May 9, 2020 at 3:51 AM Chris Angelico wrote: > &g

[Python-ideas] Re: Introduce 100 more built-in exceptions

2020-05-09 Thread Ram Rachum
Hey, I just found a good example for the unpacking errors I suggested: def topological_sort(graph: networkx.DiGraph) -> tuple: try: (zero_node,) = (node for node in graph if not graph.neighbors(node)) except TooFewToUnpackError: raise

[Python-ideas] Re: Introduce 100 more built-in exceptions

2020-05-09 Thread Ram Rachum
On Sat, May 9, 2020 at 8:09 PM Alex Hall wrote: > On Sat, May 9, 2020 at 7:02 PM Ram Rachum wrote: > >> >> Besides elegance, the above code can be optimized with short-circuit >> logic for the TooManyToUnpackError, assuming that doesn't break backward >> comp

[Python-ideas] islice with actual slices

2020-05-09 Thread Ram Rachum
Here's an idea I've had. How about instead of this: itertools.islice(iterable, 7, 20) We'll just have: itertools.islice(iterable)[7:20] Advantages: 1. More familiar slicing syntax. 2. No need to awkwardly use None when you're interested in just specifying the end of the slice without

[Python-ideas] Re: islice with actual slices

2020-05-09 Thread Ram Rachum
On Sat, May 9, 2020 at 12:58 PM Paul Moore wrote: > > Why would you use islice(x, None, 10)? islice(x, 10) does the same... > I guess you might occasionally do islice(x, None, end, step), but that > seems fairly rare. > My mistake, I meant islice(x, 10, None) where you're doing the slice [10:].

[Python-ideas] len(path) == len(str(path))

2020-05-24 Thread Ram Rachum
Hi everyone, I submitted a PR today, and Serhiy decided it needs a discussion on python-ideas and agreement from core developers before it could go forward. BPO: https://bugs.python.org/issue40752 PR: https://github.com/python/cpython/pull/20348 Today I wrote a script and did this:

[Python-ideas] Re: len(path) == len(str(path))

2020-05-24 Thread Ram Rachum
Well, looks like this proposal is dead in the water. Thanks for your opinions everybody, I'll close the PR. Also, for Alex and Richard, `path.parts` would do the trick. On Sun, May 24, 2020 at 2:55 PM Richard Damon wrote: > On 5/24/20 7:27 AM, Ram Rachum wrote: > > Hi everyone,

[Python-ideas] Re: Function composition

2020-05-24 Thread Ram Rachum
Speaking of evil, another evil idea would be to write code that modifies the ast and changes @ between functions to call a compose function instead. On Sun, May 24, 2020, 18:21 Steven D'Aprano wrote: > On Sun, May 24, 2020 at 10:49:45AM -0400, David Mertz wrote: > > > But how would you go about

[Python-ideas] Re: len(path) == len(str(path))

2020-05-24 Thread Ram Rachum
wrote: > > On Sunday, May 24, 2020, at 08:07 -0400, Steven D'Aprano wrote: > > > On Sun, May 24, 2020 at 02:27:00PM +0300, Ram Rachum wrote: > > > >> Today I wrote a script and did this: > >> > >> sorted(paths, key=lambda path: len(str(path)), rev

[Python-ideas] Weakrefs for lru_cache?

2020-10-15 Thread Ram Rachum
Hi everyone, For many years, I've used a `cache` decorator that I built for caching Python functions. Then `functools.lru_cache` was implemented, which is much more standard. However, as far as I

[Python-ideas] Re: Weakrefs for lru_cache?

2020-10-15 Thread Ram Rachum
e > interesting debates about who’s fault it is. > > Irit > > On 15 Oct 2020, at 18:53, Ram Rachum wrote: > >  > Hi everyone, > > For many years, I've used a `cache` decorator that I built > <https://github.com/cool-RR/python_toolbox/blob/master/python_toolbox/cachin

[Python-ideas] Re: Weakrefs for lru_cache?

2020-10-15 Thread Ram Rachum
, or am I not > understanding your suggestion? > > > October 15, 2020 1:49 PM, "Ram Rachum" > wrote: > > Hi everyone, > For many years, I've used a `cache` decorator that I built > <https://github.com/cool-RR/python_toolbox/blob/master/python_toolbox

[Python-ideas] Re: Weakrefs for lru_cache?

2020-10-16 Thread Ram Rachum
for me in one line. On Fri, Oct 16, 2020 at 11:45 AM Irit Katriel wrote: > You can use a global WeakKeyDictionary keyed by the object to achieve the > same without having anything on the object. > > > On Friday, October 16, 2020, 09:37:05 AM GMT+1, Ram Rachum > wrote: > > D

[Python-ideas] Re: Weakrefs for lru_cache?

2020-10-16 Thread Ram Rachum
Did you mean like keeping a hidden attribute on the object with the result? Well, that'd require manually keeping track of these attributes for each method I'm caching. I do that sometimes, but it's verbose. On Fri, Oct 16, 2020 at 11:26 AM Paul Moore wrote: > On Fri, 16 Oct 2020 at 08:42,

[Python-ideas] Re: Weakrefs for lru_cache?

2020-10-16 Thread Ram Rachum
That's similar to my use case. Big mutable object (right now a state in a multi-agent simulation) with lots of methods that I want to cache. "Given that it's not really hard to write your own caching decorator, I don't feel like this needs to change the API of lru_cache." Well, given that it's

[Python-ideas] Re: Weakrefs for lru_cache?

2020-10-16 Thread Ram Rachum
Well, I can also write a decorator that does lru_cache, but there are a lot of advantages that it's available in the standard library... On Fri, Oct 16, 2020 at 12:35 PM Antoine Pitrou wrote: > On Fri, 16 Oct 2020 11:34:08 +0300 > Ram Rachum wrote: > > Did you mean like keep

[Python-ideas] Tracebacks for C code in Python

2020-08-15 Thread Ram Rachum
Here's something that's been bugging me for years. I'll suggest something, but since I'm a total newbie about this area, it's possible that everything I'm saying is impossible or doesn't make sense. I'm working with some Pandas code now, and there's an exception because I'm doing something wrong.

[Python-ideas] Re: Allowing assertEqual etc to take multiple items

2020-05-28 Thread Ram Rachum
On Thu, May 28, 2020 at 11:42 AM Serhiy Storchaka wrote: > 28.05.20 11:02, Ram Rachum пише: > > I recently submitted this PR > > <https://github.com/more-itertools/more-itertools/pull/430/files>, and > I > > had to use assertSequenceEqual twice, just because I wan

[Python-ideas] Allowing assertEqual etc to take multiple items

2020-05-28 Thread Ram Rachum
Hi guys! I'm a unittest newbie, so it's possible there's a better solution than what I'm proposing here. If there is, please let me know. I recently submitted this PR , and I had to use assertSequenceEqual twice, just because I

[Python-ideas] Re: Default behavior for random.sample when no k

2020-08-03 Thread Ram Rachum
On Mon, Aug 3, 2020 at 3:20 PM wrote: > Ram Rachum wrote:. > > I notice that the random.sample function doesn't have a default behavior > > set when you don't specify k. This is fortunate, because we could make > > that behavior just automatically take the length of the

[Python-ideas] Re: Default behavior for random.sample when no k

2020-08-01 Thread Ram Rachum
similar to `.sort()` and `sorted()` or > `.reverse()` and `reversed()`. > > On Sat, Aug 1, 2020 at 7:59 PM Ram Rachum wrote: > >> When writing some code now, I needed to produce a shuffled version of >> `range(10, 10 ** 5)`. >> >> This is one way to

[Python-ideas] Default behavior for random.sample when no k

2020-08-01 Thread Ram Rachum
When writing some code now, I needed to produce a shuffled version of `range(10, 10 ** 5)`. This is one way to do it: shuffled_numbers = list(range(10, 10 ** 5)) random.shuffle(shuffled_numbers) I don't like it because (1) it's too imperative and (2) I'm calling the list "shuffled" even before

[Python-ideas] Re: Default behavior for random.sample when no k

2020-08-02 Thread Ram Rachum
I submitted a patch now, but Serhiy showed me that it's already been proposed before, and rejected by Raymond Hettinger and Terry Reedy in issues 26393 and 27964. On Sun, Aug 2, 2020 at 8:05 AM Steven D'Aprano wrote: > On Sat, Aug 01, 2020 at 08:54:16PM +0300, Ram Rachum wrote: > &g

[Python-ideas] Automatic notification when your PR test fails or succeeds

2020-06-05 Thread Ram Rachum
Hi guys, I'm not sure whether this is the right mailing list for this, because it's more for the Python development process on GitHub than Python itself. If this belongs somewhere else, let me know. When you open a PR to CPython, it would be cool if there was an option to get email notifications

[Python-ideas] Re: Tracebacks for C code in Python

2020-08-16 Thread Ram Rachum
Thanks for the responses everyone. On Sun, Aug 16, 2020 at 9:43 AM Marco Sulla wrote: > You probably wants also the python extension for gdb, to go faster to > the interesting code: > https://stackoverflow.com/q/41160447/1763602 > ___ > Python-ideas

[Python-ideas] Support reversed(itertools.chain(x, y, z))

2021-01-08 Thread Ram Rachum
Today I had a need: I had a tuple of dynamic sequence-like objects. I wanted to iterate on them reversed, starting with items of the last one and slowly making my way towards the first one. In short, I want `reversed(itertools.chain(x, y, z))` that behaves like `itertools.chain(map(reversed, (z,

[Python-ideas] Re: Bring back PEP 501

2021-05-07 Thread Ram Rachum
Hi Marc. On Fri, May 7, 2021 at 11:32 PM M.-A. Lemburg wrote: > On 07.05.2021 21:40, Nick Humrich wrote: > > PEP 501 was deferred because more learning and time was wanted after > introducing > > f-strings. Now that it has been 5 years, I wonder what the possibilities > of > > revisiting PEP

[Python-ideas] Re: Bring back PEP 501

2021-05-07 Thread Ram Rachum
+1 On Fri, May 7, 2021 at 10:42 PM Nick Humrich wrote: > PEP 501 was deferred because more learning and time was wanted after > introducing f-strings. Now that it has been 5 years, I wonder what the > possibilities of revisiting PEP 501 are. > > I recently had the experience of using javascript

[Python-ideas] Re: concurrent.futures.ProcessPoolExecutor(restart_workers=True)

2021-06-26 Thread Ram Rachum
gt; >> billiard a multiprocessing py2 fork/backport has >> https://billiard.readthedocs.io/en/latest/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool >> with maxtasksperchild >> >> On Sat, 26 Jun 2021, 16:57 Ram Rachum, wrote: >

[Python-ideas] concurrent.futures.ProcessPoolExecutor(restart_workers=True)

2021-06-26 Thread Ram Rachum
Hi guys, I want to have a version of `concurrent.futures.ProcessPoolExecutor` in which every worker process shuts down after each task. I want this because I believe I have a memory leak in my program that I wasn't able to fix. (Possibly it's in C extensions that I use.) Since I'm going to use a

[Python-ideas] Subject=Re: Re: concurrent.futures.ProcessPoolExecutor(restart_workers=True)

2021-06-26 Thread Ram Rachum
Thank you, that's helpful. Though I really like the future interface, I've used it many times while I never used `multiprocessing.pool.Pool` or its `AsyncResult`. I worry that some of the expectations I've grown to have from `Future` objects would be broken here. It would be nice if this feature

[Python-ideas] Re: Revisiting a frozenset display literal

2022-01-29 Thread Ram Rachum
+1 I would appreciate being able to create a frozenset using f{1, 2, 3}. This will also make the `repr` of frozensets shorter. On Sun, Jan 16, 2022 at 10:33 AM Steven D'Aprano wrote: > Inspired by this enhancement request: > > https://bugs.python.org/issue46393 > > I thought it might be time to

[Python-ideas] re.match(pattern, string, require=True)

2023-10-21 Thread Ram Rachum
Hey, I bet this has been discussed before but I couldn't find it. I'd appreciate it if anyone could point me to that thread. I'm sick of seeing "AttributeError: 'NoneType' object has no attribute 'foo'" whenever there's a `re.match` operation that fails while the code expects it to succeed. What

[Python-ideas] Re: re.match(pattern, string, require=True)

2023-10-21 Thread Ram Rachum
> Paul > > On Sat, 21 Oct 2023 at 11:38, Ram Rachum wrote: > >> Hey, >> >> I bet this has been discussed before but I couldn't find it. I'd >> appreciate it if anyone could point me to that thread. >> >> I'm sick of seeing "AttributeError:

[Python-ideas] Re: re.match(pattern, string, require=True)

2023-10-21 Thread Ram Rachum
On Sat, Oct 21, 2023 at 10:30 PM Chris Angelico wrote: > > > I love that, but it mostly makes sense for "if there's a match do this, > otherwise do that" where most cases fall into "I'm absolutely sure there's > a match here and here's what we should do with that match", and when that >

[Python-ideas] Re: re.match(pattern, string, require=True)

2023-10-21 Thread Ram Rachum
On Sat, Oct 21, 2023 at 10:01 PM Chris Angelico wrote: > On Sat, 21 Oct 2023 at 21:57, Ram Rachum wrote: > > What about an if with the match inside it? > > if m := re.match(...): > ... > > That's one of the motivating examples behind the walrus after all. > I lov

[Python-ideas] Re: zip(x, y, z, strict=True)

2022-12-01 Thread Ram Rachum
ror" :) On Mon, Apr 20, 2020 at 8:42 PM Ram Rachum wrote: > Here's something that would have saved me some debugging yesterday: > > >>> zipped = zip(x, y, z, strict=True) > > I suggest that `strict=True` would ensure that all the iterables have been > exh

[Python-ideas] Re: Add mechanism to check if a path is a junction (for Windows)

2022-11-07 Thread Ram Rachum
+1 on adding Path.is_junction() that returns False on non-Windows systems. (I'm a Windows user and I use junctions as well.) On Tue, Nov 8, 2022 at 9:24 AM Charles Machalow wrote: > I'm not technical enough here to try to argue which it is closer to. We > can say it's like so and so in