[Python-ideas] PEP 663: Improving and Standardizing Enum str(), repr(), and format() behaviors

2021-09-10 Thread Ethan Furman
PEP 663 is presented below for your viewing pleasure. Comments, questions, and concerns are welcome. PEP: 663 Title: Improving and Standardizing Enum str(), repr(), and format() behaviors Version: $Revision$ Last-M

[Python-ideas] Re: Different exceptions for assert

2021-09-10 Thread Stephen J. Turnbull
Juancarlo A$(D+P(Bez writes: > assert cond: > # Write some debugging info to a log. > ... > raise ExtType(args) > > I like the idea of preparing the arguments for the assertion message in a > context that gets executed only when the assertion fails. The mor

[Python-ideas] Re: Different exceptions for assert

2021-09-10 Thread Rob Cliffe via Python-ideas
On 10/09/2021 23:38, Juancarlo Añez wrote: Following with the ideas on this thread, it would be possible for -OO to turn off only assertions with exceptions that descend from AssertionError. I think this would be confusing, as contrasted with the simple rule that -OO turns off assertion

[Python-ideas] Re: Different exceptions for assert

2021-09-10 Thread Juancarlo Añez
assert cond: # Write some debugging info to a log. ... raise ExtType(args) I like the idea of preparing the arguments for the assertion message in a context that gets executed only when the assertion fails. On Thu, Sep 9, 2021 at 7:16 PM MRAB wrote: > On 2021-09-0

[Python-ideas] Re: Different exceptions for assert

2021-09-10 Thread Juancarlo Añez
Christopher, The *if* version has the condition inverted, and it's structure makes it look as part of the algorithm, instead of an assertion over an invariant. Following with the ideas on this thread, it would be possible for -OO to turn off only assertions with exceptions that descend from Asser

[Python-ideas] Re: Iterate through members of enum.Flag

2021-09-10 Thread Ethan Furman
On 9/10/21 4:19 AM, matt...@matthewstocks.co.uk wrote: > My proposal is that iterating through a member of a Flag enum will return all the constituent members. It's a good proposal, and is already in 3.11. If you want the functionality now you can use the aenum [0] library. -- ~Ethan~ [0]

[Python-ideas] Iterate through members of enum.Flag

2021-09-10 Thread matthew
My proposal is that iterating through a member of a Flag enum will return all the constituent members. Demonstration Setup: class FlagEnum(enum.Flag): A = enum.auto() B = enum.auto() C = enum.auto() FlagCombo = FlagEnum.A | FlagEnum.B My proposed change would cause the following to

[Python-ideas] Re: Different exceptions for assert

2021-09-10 Thread Marc-Andre Lemburg
On 10.09.2021 05:49, Steven D'Aprano wrote: > What I question is that allowing assert to raise non-assertions will > lead to *more* resilient software rather than less. > > I know far too many people who insist on abusing assertions as a lazy > way to validate caller- or user-supplied data, whic

[Python-ideas] Re: Different exceptions for assert

2021-09-10 Thread Stéfane Fermigier
And 4) DBC constraints also become more useful than standard assertions when used in the context of a class hierarchy. I.e. preconditions, postconditions and invariants should be stronger (or sometimes weaker, IIRC, there are subtle rules related to variance and contravariance) for subclasses than

[Python-ideas] Re: Different exceptions for assert

2021-09-10 Thread Stéfane Fermigier
On Fri, Sep 10, 2021 at 7:30 AM Steven D'Aprano wrote: > > [...] If we are seriously considering DBC for Python, [...] As I think I wrote in the previous thread about DBC in Python, there are already several DBC libraries on PyPI and we should precisely evaluate both their design and impact (e.