Re: [Python-ideas] Support WHATWG versions of legacy encodings

2018-01-17 Thread Soni L.
On 2018-01-17 03:30 AM, Stephen J. Turnbull wrote: Soni L. writes: > This is surprising to me because I always took those encodings to > have those fallbacks [to raw control characters]. ISO-8859-1 implementations do, for historical reasons AFAICT. And they frequently produce mojibake an

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

2018-01-17 Thread Sylvain MARIE
(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 requirement is about *catching* unwanted/uncontrolled/heterogenous exceptions happening in the underlyin

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] Support WHATWG versions of legacy encodings

2018-01-17 Thread Chris Barker
On Tue, Jan 16, 2018 at 9:30 PM, Stephen J. Turnbull < [email protected]> wrote: > In what context? WHAT-WG's encoding standard is *all about browsers*. > If a codec is feeding text into a process that renders them all as > glyphs for a human to look at, that's one thing. The c

Re: [Python-ideas] Support WHATWG versions of legacy encodings

2018-01-17 Thread Rob Speer
I'm going to push back on the idea that this should only be used for decoding, not encoding. The use case I started with -- showing people how to fix mojibake using Python -- would *only* use these codecs in the encoding direction. To fix the most common case of mojibake, you encode it as web-1252

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: ra

Re: [Python-ideas] Support WHATWG versions of legacy encodings

2018-01-17 Thread Nathaniel Smith
On Wed, Jan 17, 2018 at 10:13 AM, Rob Speer wrote: > I'm going to push back on the idea that this should only be used for > decoding, not encoding. > > The use case I started with -- showing people how to fix mojibake using > Python -- would *only* use these codecs in the encoding direction. To fi

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 should just add a func

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 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 optimisation for that specif

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

2018-01-17 Thread Steven D'Aprano
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 AssertionError("x must be positive") > else:

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 Asserti