[Python-ideas] Re: factory for sentinel objects

2023-08-31 Thread Matthias Görgens
Seems nice. Just write a library and upload it to one of the usual places? On Thu, 31 Aug 2023, 16:54 Tim Hoffmann via Python-ideas, < python-ideas@python.org> wrote: > The standard pattern to create a sentinel in Python is > > >>> Unset = object() > > While this is often good enough, it has

[Python-ideas] Re: `join` method for the `list` class ... `list.join`

2023-06-06 Thread Matthias Görgens
This is sometimes a nice function to have. For example, Haskell has a similar function: https://hackage.haskell.org/package/base-4.18.0.0/docs/Data-List.html#v:intercalate that I use in real code every once in a while. But I don't think you need to stick this function in the standard library. A

[Python-ideas] Re: Allowing `str.format` to format one or more parameters instead of all parameters

2023-04-28 Thread Matthias Görgens
hat if it's done not by format method but by a separete method, say, > format_partially or something? The method is different from format > also in that it should leave "{{" and "}}" unaltered. > > On Fri, 28 Apr 2023 at 00:05, Matthias Görgens > wrote: &g

[Python-ideas] Re: Allowing `str.format` to format one or more parameters instead of all parameters

2023-04-27 Thread Matthias Görgens
What is the use case for this? Does it have any use case that's not already served by functools.partial? As far as I can tell, this proposal would turn buggy code that currently throws an obvious exception into code that silently does the wrong thing. This seems more appropriate for PHP or

[Python-ideas] Re: Allowing `str.format` to format one or more parameters instead of all parameters

2023-04-21 Thread Matthias Görgens
What's the use-case for this? Have you looked into using functools.partial instead? On Sat, 22 Apr 2023, 06:23 Samuel Muldoon, wrote: > Consider the following string: > > x = r"\mathjax{{color}}{{text}}" > > string `x` contains two parameters named `color` and the other named `text > `. > >

[Python-ideas] Re: Better (?) PRNG

2022-12-06 Thread Matthias Görgens
On Tue, 15 Nov 2022 at 00:14, David Mertz, Ph.D. wrote: > In general, all PRNGs are deterministic, and by relying on a known seed, > the Nth element in a sequence of random numbers can always be > reconstructructed. However, if a large number of random numbers are used, > certain replication

[Python-ideas] Re: Feedback before submission of PEP 661: Sentinel Values

2022-09-11 Thread Matthias Görgens
Btw, just to give some context: The reason we need sentinels at all is because our APIs don't like to wrap the happy case. As an example: So in Python, when you do {'a': 'foo'}.get('a') you get 'foo' directly. That's convenient. In eg Haskell the equivalent operation gives you a wrapped 'foo'.

[Python-ideas] Re: Add InvalidStateError to the standard exception hierarchy

2022-09-02 Thread Matthias Görgens
> > It depends on context whether it makes sense to define a custom exception, > and I agree that I frequently should define a custom exception. In that > case though, it would still be nice to have an appropriate generic > exception for that to inherit from, just as I would inherit from >

[Python-ideas] Re: Add InvalidStateError to the standard exception hierarchy

2022-09-01 Thread Matthias Görgens
> > If the target of the call isn't in an appropriate state, isn't that a > bug in the constructor that it allows you to construct objects that are > in an invalid state? > > You should fix the object so that it is never in an invalid state rather > than blaming the caller. > You can't really do

[Python-ideas] Re: A standard library Multiset implementation?

2022-08-13 Thread Matthias Görgens
Hi Brian, It sounds like a high quality third-party library that has both a multiset implementation and the itertools you needed would fulfill most of your requirements? Code in the standard library isn't magically of higher quality. Compare eg standard library dataclasses with dataclassy. As a