Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-19 Thread Sylvain MARIE
> I haven't yet seen any justification for syntax here. The nearest I've seen > is that this "ensure" action is more like: > > try: > cond = x >= 0 > except BaseException: > raise AssertionError("x must be positive") > else: > if not cond: > raise AssertionError("x must be

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-18 Thread Steven D'Aprano
On Thu, Jan 18, 2018 at 08:00:01PM -0800, Guido van Rossum wrote: > On Thu, Jan 18, 2018 at 7:51 PM, Nikolas Vanderhoof < > nikolasrvanderh...@gmail.com> wrote: > > > I sometimes wish that Python included a richer set of assertions rather > >> than just a single `assert` keyword. Something like

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-18 Thread Nikolas Vanderhoof
Thank you for your explanation! ᐧ On Thu, Jan 18, 2018 at 11:00 PM, Guido van Rossum wrote: > On Thu, Jan 18, 2018 at 7:51 PM, Nikolas Vanderhoof < > nikolasrvanderh...@gmail.com> wrote: > >> I sometimes wish that Python included a richer set of assertions rather >>> than just

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-18 Thread Guido van Rossum
On Thu, Jan 18, 2018 at 7:51 PM, Nikolas Vanderhoof < nikolasrvanderh...@gmail.com> wrote: > I sometimes wish that Python included a richer set of assertions rather >> than just a single `assert` keyword. Something like Eiffel's concept of >> pre-conditions, post-conditions and invariants, where

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-18 Thread Nikolas Vanderhoof
> > I sometimes wish that Python included a richer set of assertions rather > than just a single `assert` keyword. Something like Eiffel's concept of > pre-conditions, post-conditions and invariants, where each can be > enabled or disabled independently. Has something like this been proposed for

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-17 Thread Ethan Furman
On 01/17/2018 10:59 PM, Steven D'Aprano wrote: On Thu, Jan 18, 2018 at 05:22:06PM +1100, Chris Angelico wrote: I haven't yet seen any justification for syntax here. The nearest I've seen is that this "ensure" action is more like: try: cond = x >= 0 except BaseException: raise

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-17 Thread Chris Angelico
On Thu, Jan 18, 2018 at 4:21 PM, Steve Barnes wrote: > 1. For asserts that should not be disabled we could have an always > qualifier optionally added to assert, either as "assert condition > exception always" or "assert always condition exception", that disables > the

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-17 Thread Steve Barnes
On 17/01/2018 17:19, Nikolas Vanderhoof wrote: > I think having a means for such validations separate from assertions > would be helpful. > However, I agree with Steven that 'validate' would be a bad keyword choice. > Besides breaking compatibility with programs that use 'validate', it > would

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-17 Thread Nick Coghlan
On 18 January 2018 at 07:46, Steven D'Aprano wrote: > To justify a keyword, it needs to do something special that a built-in > function can't do, like delayed evaluation (without wrapping the > expression in a function). My reaction to these threads for a while has been "We

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-17 Thread Steven D'Aprano
On Wed, Jan 17, 2018 at 12:19:51PM -0500, Nikolas Vanderhoof wrote: > I think having a means for such validations separate from assertions would > be helpful. What semantics would this "validate" statement have, and how would it be different from what we can write now? if not condition:

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-17 Thread Nikolas Vanderhoof
I think having a means for such validations separate from assertions would be helpful. However, I agree with Steven that 'validate' would be a bad keyword choice. Besides breaking compatibility with programs that use 'validate', it would break wsgiref.validate

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-17 Thread Sylvain MARIE
ylvain.ma...@schneider-electric.com> Cc : Python-Ideas <python-ideas@python.org> Objet : Re: [Python-ideas] Repurpose `assert' into a general-purpose check I fixed the reply-to this time, looks like you're still getting messed up by Google Groups. On 16 January 2018 at 16:25, smarie <sy

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-16 Thread Steven D'Aprano
On Tue, Jan 16, 2018 at 07:37:29AM -0800, smarie wrote: [...] > > The problem with a statement called "validate" is that it will break a > > huge number of programs that already include functions and methods using > > that name. > > > > You definitely make a point here. But that would be the

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-16 Thread Juancarlo Añez
Perhaps the OP can look into Python macro libraries to get the wanted syntax? https://github.com/lihaoyi/macropy On Tue, Jan 16, 2018 at 2:35 PM, Paul Moore wrote: > On 16 January 2018 at 17:36, Sylvain MARIE > wrote: > > (trying with

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-16 Thread Paul Moore
On 16 January 2018 at 17:36, Sylvain MARIE wrote: > (trying with direct reply this time) > >> Why do you do this? What's the requirement for delaying evaluation of the >> condition? > > Thanks for challenging my poorly chosen examples :) > > The primary

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-16 Thread Paul Moore
I fixed the reply-to this time, looks like you're still getting messed up by Google Groups. On 16 January 2018 at 16:25, smarie wrote: > Let's consider this example where users want to define on-the-fly one of the > validation functions, and combine it with

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-16 Thread smarie
Thanks Paul Le mardi 16 janvier 2018 16:56:57 UTC+1, Paul Moore a écrit : > > > Why does this need to be a statement at all? Unlike assert, it's > > always executed, so it can be defined as a simple function > Very good point. Actually that's what I already provide in valid8 with the

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-16 Thread Paul Moore
Grr, Google Groups gateway messes up reply-to. Apologies to anyone who gets a double-post, please can posters ensure that reply-to is set to the list, and *not* to the Google Groups gateway? Thanks. Paul On 16 January 2018 at 15:54, Paul Moore wrote: > On 16 January 2018 at

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-16 Thread smarie
Le mardi 16 janvier 2018 11:24:34 UTC+1, Steven D'Aprano a écrit : > > That's not a bug, or even a problem ("wrong"), it is the very purpose of > assert. Assertions are intended to allow the end user to disable the > checks. > > If you, the developer, don't want a check to be disabled, then

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-16 Thread smarie
Le mardi 16 janvier 2018 16:37:29 UTC+1, smarie a écrit : > > > validate is_foo_compliant(x) or is_bar_compliant(x) > ValidationError(message) > This was a typo in this case since we use the base ValidationError it even would simplify to validate is_foo_compliant(x) or

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-16 Thread Steven D'Aprano
On Tue, Jan 16, 2018 at 01:38:25AM -0800, smarie wrote: > Typically ‘assert isfinite(x)‘ is today a good example of what is wrong: > >1. it can be disabled globally by end-users even if the lib developer >does not want it, That's not a bug, or even a problem ("wrong"), it is the very

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-16 Thread Serhiy Storchaka
16.01.18 11:38, smarie пише: You can find my attempt to do that in the valid8 project https://smarie.github.io/python-valid8 , with the 'assert_valid(...)' function. With the current language limitations I could not define something as simple as

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2018-01-16 Thread smarie
(for some reason google groups has accepted the message but the mailing list rejected it. Re-posting it, sorry for the inconvenience) Le mardi 28 novembre 2017 04:22:13 UTC+1, Nathan Schneider a écrit : > > > I think it would be interesting to investigate how assert statements are > used in the

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-29 Thread Petr Viktorin
On 11/29/2017 08:31 PM, Barry Warsaw wrote: Nathan Schneider wrote: I think it would be interesting to investigate how assert statements are used in the wild. I can think of three kinds of uses: assert statements are also a form of executable documentation. It says something like "I think

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-29 Thread Barry Warsaw
Nathan Schneider wrote: > I think it would be interesting to investigate how assert statements are > used in the wild. I can think of three kinds of uses: assert statements are also a form of executable documentation. It says something like "I think the internal state of my code must be this

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Nick Coghlan
On 29 November 2017 at 02:03, Ivan Pozdeev via Python-ideas wrote: > On 28.11.2017 16:36, Nick Coghlan wrote: >> I'll make the same observation I usually do each time one of these >> threads comes up: >> >> * I'm opposed to making assert substantially different from the

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Serhiy Storchaka
28.11.17 15:36, Nick Coghlan пише: * I'm opposed to making assert substantially different from the way it works now If sometimes we will change assert I would prefer to make it more similar to assert in pytest. Output values of the final and intermediate expressions. The hardest problem --

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Soni L.
On 2017-11-28 04:27 PM, Ivan Pozdeev via Python-ideas wrote: On 28.11.2017 20:23, Ethan Furman wrote On 11/28/2017 08:03 AM, Ivan Pozdeev via Python-ideas wrote: On 28.11.2017 16:36, Nick Coghlan wrote:    it doesn't need to be a statement any more > Another benefit of a statement vs

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Ivan Pozdeev via Python-ideas
On 28.11.2017 20:23, Ethan Furman wrote On 11/28/2017 08:03 AM, Ivan Pozdeev via Python-ideas wrote: On 28.11.2017 16:36, Nick Coghlan wrote:    it doesn't need to be a statement any more > Another benefit of a statement vs function is only evaluating the error-related arguments when

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Ethan Furman
On 11/28/2017 08:03 AM, Ivan Pozdeev via Python-ideas wrote: On 28.11.2017 16:36, Nick Coghlan wrote: it doesn't need to be a statement any more > Another benefit of a statement vs function is only evaluating the error-related arguments when there's an error The bulk of any processing

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Steven D'Aprano
On Tue, Nov 28, 2017 at 10:11:46AM +0300, Ivan Pozdeev via Python-ideas wrote: > I invite you to show me a single use case for those "assertions" because > after ~20 years of experience in coding (that included fairly large > projects), I've yet to see one. I already mentioned not one but

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Elazar
On Tue, Nov 28, 2017 at 6:08 PM Ivan Pozdeev via Python-ideas < python-ideas@python.org> wrote: > On 28.11.2017 16:36, Nick Coghlan wrote: > > > On 28 November 2017 at 15:41, Steven D'Aprano > wrote: > >> On Tue, Nov 28, 2017 at 05:12:36AM +0300, Ivan Pozdeev via

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Ivan Pozdeev via Python-ideas
On 28.11.2017 16:36, Nick Coghlan wrote: On 28 November 2017 at 15:41, Steven D'Aprano wrote: On Tue, Nov 28, 2017 at 05:12:36AM +0300, Ivan Pozdeev via Python-ideas wrote: Unlike C, Python does the aforementioned checks all the time, i.e. it's effectively always in

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread David Mertz
I've used Python for 20 years, and programming in general for about 40 now. I think almost EVERY large code base I've seen used asserts in their intended way. I frequently use them myself in a way differentiated (subtly) from 'if cond: raise SomeException'. I honestly don't know how Ivan has

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Soni L.
On 2017-11-28 11:36 AM, Nick Coghlan wrote: On 28 November 2017 at 15:41, Steven D'Aprano wrote: On Tue, Nov 28, 2017 at 05:12:36AM +0300, Ivan Pozdeev via Python-ideas wrote: Unlike C, Python does the aforementioned checks all the time, i.e. it's effectively always in

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Nick Coghlan
On 28 November 2017 at 15:41, Steven D'Aprano wrote: > On Tue, Nov 28, 2017 at 05:12:36AM +0300, Ivan Pozdeev via Python-ideas wrote: >> Unlike C, Python does the aforementioned checks all the time, i.e. it's >> effectively always in "debug mode". > > Apart from -O which

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Steven D'Aprano
On Tue, Nov 28, 2017 at 05:54:12PM +0900, Stephen J. Turnbull wrote: > I understand the point made elsewhere about scientists' thinking about > "assert", but as a scientist myself, I disagree. It is very useful to > me to distinguish between validating data and validating algorithms. > "assert"

[Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Stephen J. Turnbull
Ivan Pozdeev via Python-ideas writes: > The `assert' statment was created the same as in previous languages like > C/C++: a check to only do in debug mode, when you can't yet trust your > code to manage and pass around internal data correctly. Examples are > array bounds and object state

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread M.-A. Lemburg
On 28.11.2017 03:28, Ivan Pozdeev via Python-ideas wrote: > On 28.11.2017 5:19, Chris Angelico wrote: > >> Actually, Python does have a way of disabling assertions (the -O >> flag), so they should be treated the same way they are in C. >> Assertions should not be used as shorthands for "if cond:

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-28 Thread Ivan Pozdeev via Python-ideas
On 28.11.2017 10:22, Elazar wrote: Just a note : in typechecked code (such as mypy's source code) assert is used to guide the checker: assert isinstance(x, CallableType) return x.args  # checker knows it's valid So the assert becomes a kind of type annotation. The runtime check helps during

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-27 Thread Elazar
Just a note : in typechecked code (such as mypy's source code) assert is used to guide the checker: assert isinstance(x, CallableType) return x.args # checker knows it's valid So the assert becomes a kind of type annotation. The runtime check helps during tests, but is not that important -

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-27 Thread Ivan Pozdeev via Python-ideas
On 28.11.2017 8:59, Steven D'Aprano wrote: On Tue, Nov 28, 2017 at 07:35:45AM +0300, Ivan Pozdeev via Python-ideas wrote: Actually, the way I'm using them,     assert condition, "error message", type would probably be the most expressive way. I disagree that is expressive -- I call it

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-27 Thread Steven D'Aprano
On Tue, Nov 28, 2017 at 07:35:45AM +0300, Ivan Pozdeev via Python-ideas wrote: > Actually, the way I'm using them, > >     assert condition, "error message", type > > would probably be the most expressive way. I disagree that is expressive -- I call it *misleading*. I see something which

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-27 Thread Steven D'Aprano
On Tue, Nov 28, 2017 at 05:12:36AM +0300, Ivan Pozdeev via Python-ideas wrote: > The `assert' statment was created the same as in previous languages like > C/C++: a check to only do in debug mode, when you can't yet trust your > code to manage and pass around internal data correctly. That's not

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-27 Thread Ivan Pozdeev via Python-ideas
On 28.11.2017 6:34, Ned Batchelder wrote: You are proposing:     assert condition, type, value Not specifically this, that's just an example. Actually, the way I'm using them,     assert condition, "error message", type would probably be the most expressive way. Why not just use Python

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-27 Thread Ned Batchelder
On 11/27/17 9:12 PM, Ivan Pozdeev via Python-ideas wrote: The `assert' statment was created the same as in previous languages like C/C++: a check to only do in debug mode, when you can't yet trust your code to manage and pass around internal data correctly. Examples are array bounds and object

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-27 Thread Nathan Schneider
On Mon, Nov 27, 2017 at 9:28 PM, Ivan Pozdeev via Python-ideas < python-ideas@python.org> wrote: > On 28.11.2017 5:19, Chris Angelico wrote: > > Actually, Python does have a way of disabling assertions (the -O >> flag), so they should be treated the same way they are in C. >> Assertions should

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-27 Thread Jason Maldonis
> > Assertions should not be used as shorthands for "if cond: raise Exc" > in the general case. > I'm just a lurker and usually I agree with why the suggested features shouldn't be implemented, but I actually might chime in to pitch this one a bit more -- and I think it can be done nicely

Re: [Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-27 Thread Ivan Pozdeev via Python-ideas
On 28.11.2017 5:19, Chris Angelico wrote: Actually, Python does have a way of disabling assertions (the -O flag), so they should be treated the same way they are in C. Assertions should not be used as shorthands for "if cond: raise Exc" in the general case. I'm claiming, and provided evidence,

[Python-ideas] Repurpose `assert' into a general-purpose check

2017-11-27 Thread Ivan Pozdeev via Python-ideas
The `assert' statment was created the same as in previous languages like C/C++: a check to only do in debug mode, when you can't yet trust your code to manage and pass around internal data correctly. Examples are array bounds and object state integrity constraints. Unlike C, Python does the