[Python-ideas] Re: use type hints and slices to specify a valid numerical range, example: `Angle = int[0:361]`

2020-08-08 Thread David Mertz
On Sun, Aug 9, 2020, 12:07 AM Steven D'Aprano > > [*] For languages with bounded data types, this is more compelling. If > I think a variable will *definitely* fit in a uint8, having the static tool > tell me it might not is powerful. > > uint8 = int[0:256] > > So if it's useful to know that

[Python-ideas] Re: use type hints and slices to specify a valid numerical range, example: `Angle = int[0:361]`

2020-08-08 Thread Steven D'Aprano
On Sat, Aug 08, 2020 at 08:13:53PM -0400, David Mertz wrote: > Yes, this is absolutely doable! I guess my argument in several posts is > that this simple level of analysis of "possible bounds violation" is rarely > useful (at least in a Python context[*]). Vastly more complicated formal > proofs

[Python-ideas] Re: Inline Try-Except Clause

2020-08-08 Thread Stephen J. Turnbull
Rob Cliffe via Python-ideas writes: > Steven d'Aprano wrote: > > You don't have to agree with Serhiy's preference to recognise that there > > are cases where this proposal will save no lines of code. And probably > > not rare cases -- I expect that they will be much more common than the > >

[Python-ideas] Re: use type hints and slices to specify a valid numerical range, example: `Angle = int[0:361]`

2020-08-08 Thread Greg Ewing
On 9/08/20 10:43 am, Guido van Rossum wrote: But integer ranges? I guess they would be useful to catch array indexing mistakes, I'm not sure they would. For an index error to be caught at compile time, the thing being indexed has to have a size known to the compiler. This was always the case

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-08-08 Thread Ricky Teachey
I misunderstood thanks for the clarification and if an apology is appropriate I gladly offer mine. On Sat, Aug 8, 2020, 9:01 PM Edwin Zimmerman wrote: > On 8/7/2020 10:47 PM, Ricky Teachey wrote: > > On Fri, Aug 7, 2020 at 9:25 PM Edwin Zimmerman > wrote: > >> On 8/7/2020 8:28 PM, Greg Ewing

[Python-ideas] Re: Changing item dunder method signatures to utilize positional arguments (open thread)

2020-08-08 Thread Edwin Zimmerman
On 8/7/2020 10:47 PM, Ricky Teachey wrote: > On Fri, Aug 7, 2020 at 9:25 PM Edwin Zimmerman > wrote: > > On 8/7/2020 8:28 PM, Greg Ewing wrote: > >  I don't think anyone has the appetite for a Python 4 any > > time soon. > > > I'm included in

[Python-ideas] Re: use type hints and slices to specify a valid numerical range, example: `Angle = int[0:361]`

2020-08-08 Thread David Mertz
On Sat, Aug 8, 2020, 7:40 PM Steven D'Aprano > Any checker capable of doing bounds checks would know that the range of > possible ints is unbounded in both directions, and therefore an int does > not fit into the range [1:10**9]. Hence that will be a static bounds > check failure: Just so you

[Python-ideas] Re: `property.apply` decorator

2020-08-08 Thread Roger Serwy
That's an excellent point about argument unpacking. Thank you for your feedback, I'll consider this idea resolved. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: use type hints and slices to specify a valid numerical range, example: `Angle = int[0:361]`

2020-08-08 Thread Steven D'Aprano
On Sat, Aug 08, 2020 at 01:28:59AM -0400, David Mertz wrote: > On Sat, Aug 8, 2020, 1:12 AM Steven D'Aprano > > > Static languages often check what > > bounds they can at compile time, and optionally insert bound checking > > runtime code for ambiguous places. > > > Yep. That's an assert, or

[Python-ideas] Re: use type hints and slices to specify a valid numerical range, example: `Angle = int[0:361]`

2020-08-08 Thread 2QdxY4RzWzUUiLuE
On 2020-08-08 at 18:53:36 -0400, David Mertz wrote: > ... my discovery was that "LLVM figures out Gauss' simplification and > does it in constant time no matter the N. After that I looked at the > LLVM bytecode to see, "Yup, it does." The optimizer is pretty smart > about variations in writing

[Python-ideas] Re: `property.apply` decorator

2020-08-08 Thread Steven D'Aprano
On Sat, Aug 08, 2020 at 10:22:20PM -, Roger Serwy wrote: > The property decorator, with its .setter and .deleter chaining, is a > bit cumbersome and repetitive. If we can add `.apply` as a method on > property that calls a function that returns the fget/fset/fdel/doc > arguments, it would

[Python-ideas] Re: use type hints and slices to specify a valid numerical range, example: `Angle = int[0:361]`

2020-08-08 Thread David Mertz
On Sat, Aug 8, 2020 at 5:49 PM Michael Smith wrote: > This kind of thing is so powerful, and I would love to see tooling capable > of it in the python ecosystem. I believe folks who say it's very hard to > implement correctly, but I don't know that that's a good reason not to make > the proposed

[Python-ideas] Re: Function suggestion: itertools.one()

2020-08-08 Thread Stefano Borini
+1 very useful also for me. Once in a while I have this exact scenario. Not often enough to get annoyed, but often enough that it would be nice to have. On Tue, 28 Jul 2020 at 20:27, Noam Yorav-Raphael wrote: > > Hello, > > There's a simple function that I use many times, and I think may be a

[Python-ideas] `property.apply` decorator

2020-08-08 Thread Roger Serwy
The property decorator, with its .setter and .deleter chaining, is a bit cumbersome and repetitive. If we can add `.apply` as a method on property that calls a function that returns the fget/fset/fdel/doc arguments, it would simplify instantiating the descriptor. For example: @property.apply

[Python-ideas] Re: use type hints and slices to specify a valid numerical range, example: `Angle = int[0:361]`

2020-08-08 Thread Guido van Rossum
This thread seems light on real use cases. I know there are people eager to have integer generics, since they are essential for typing numpy, pandas, tensorflow and friends. And so there are good proposals floating around for this on typing-sig; I expect implementations within a year. But integer

[Python-ideas] Re: use type hints and slices to specify a valid numerical range, example: `Angle = int[0:361]`

2020-08-08 Thread Ricky Teachey
On Sat, Aug 8, 2020 at 5:51 PM Michael Smith wrote: > This kind of thing is so powerful, and I would love to see tooling capable > of it in the python ecosystem. I believe folks who say it's very hard to > implement correctly, but I don't know that that's a good reason not to make > the proposed

[Python-ideas] Re: Inline Try-Except Clause

2020-08-08 Thread Rob Cliffe via Python-ideas
On 08/08/2020 02:16, Steven D'Aprano wrote: On Fri, Aug 07, 2020 at 06:40:33PM +0100, Rob Cliffe via Python-ideas wrote: On 07/08/2020 17:16, Serhiy Storchaka wrote: The main problem to me with the exception catching expression is that you need to add the exception name and several

[Python-ideas] Re: use type hints and slices to specify a valid numerical range, example: `Angle = int[0:361]`

2020-08-08 Thread Michael Smith
On Sat, Aug 8, 2020 at 16:41 Dominik Vilsmeier wrote: > On 08.08.20 05:48, David Mertz wrote: > > On Fri, Aug 7, 2020, 6:03 PM Paul Moore wrote: > >> > x: int[0:] # any ints greater than or equal to zero would match, >> others would fail >> > x: int[:101] # any ints less than 101 match >> >

[Python-ideas] Re: use type hints and slices to specify a valid numerical range, example: `Angle = int[0:361]`

2020-08-08 Thread Dominik Vilsmeier
On 08.08.20 05:48, David Mertz wrote: On Fri, Aug 7, 2020, 6:03 PM Paul Moore mailto:p.f.mo...@gmail.com>> wrote: > x: int[0:]  # any ints greater than or equal to zero would match, others would fail > x: int[:101]  # any ints less than 101 match > x: int[0:101:2]  # even less

[Python-ideas] Re: bpo-41231: wraps default behavior with __annotations__

2020-08-08 Thread David Caro
On 08/07 10:49, Joao S. O. Bueno wrote: > "3" would "break stuff around". > I'd be glad if "2" worked - but that have to be well documented and > easy to see. I've update the PR with improved documentation and comments to make it easier to see. At this point I'd appreciate if I get some reviews