Re: [Python-ideas] More alternate constructors for builtin type

2019-05-07 Thread Steven D'Aprano
On Tue, May 07, 2019 at 07:17:00PM +0100, Oscar Benjamin wrote: > The int function accepts all kinds of things e.g. > > >>> int('๒') > 2 > > However in my own code if that character ever got passed to int then > it would definitely indicate either a bug in the code or data > corruption

Re: [Python-ideas] More alternate constructors for builtin type

2019-05-07 Thread Steven D'Aprano
On Wed, May 08, 2019 at 08:14:50AM +1000, Cameron Simpson wrote: > On 08May2019 00:18, Greg Ewing wrote: > >Steven D'Aprano wrote: > >>That suggests a possible pair of constructors: > >> bytes.from_int(n) -> equivalent to b'%d' % n > >> bytes.ord(n) -> equivalent to bytes((n,)) > > >

Re: [Python-ideas] More alternate constructors for builtin type

2019-05-07 Thread Cameron Simpson
On 08May2019 00:18, Greg Ewing wrote: Steven D'Aprano wrote: That suggests a possible pair of constructors: bytes.from_int(n) -> equivalent to b'%d' % n bytes.ord(n) -> equivalent to bytes((n,)) I don't see how bytes.from_int(n) is any clearer about what it does than just

Re: [Python-ideas] More alternate constructors for builtin type

2019-05-07 Thread Oscar Benjamin
On Tue, 7 May 2019, 19:25 Chris Angelico, wrote: > On Wed, May 8, 2019 at 4:17 AM Oscar Benjamin > wrote: > > Admittedly the non-ASCII unicode digit example is not one that has > > actually caused me a problem but what I have had a problem with is > > floats. Given that a user of my code can

Re: [Python-ideas] More alternate constructors for builtin type

2019-05-07 Thread Ricky Teachey
One pain point in Python that constantly rears its head (at least for me) is this: def eat_iterable(yummy_iterable): if isinstance(yummy_iterable, str): raise TypeError("BLECH! Strings are ATOMIC in this context, mmkay??") tasty_list = list(yummy_iterable) # digest list...

Re: [Python-ideas] More alternate constructors for builtin type

2019-05-07 Thread Chris Angelico
On Wed, May 8, 2019 at 4:17 AM Oscar Benjamin wrote: > Admittedly the non-ASCII unicode digit example is not one that has > actually caused me a problem but what I have had a problem with is > floats. Given that a user of my code can pass in a float in place of a > string the fact that int(1.5)

Re: [Python-ideas] More alternate constructors for builtin type

2019-05-07 Thread Oscar Benjamin
On Tue, 7 May 2019 at 06:42, Christopher Barker wrote: > > Oddly, it seems everyone in this thread thinks it would be "Better" to have a > bunch of constructors, ratehr than the overloading, of only we didn't have > backward compatibility to worry about. > > I disagree -- these efficiencies are

Re: [Python-ideas] A proper way to bring real interfaces to Python

2019-05-07 Thread Stephen J. Turnbull
Serge Matveenko writes: > On Sun, May 5, 2019 at 8:23 PM Stephen J. Turnbull > wrote: > > > > Serge Matveenko writes: > > > > > So, I would like to propose adding a third main object called > > > `interface` in addition to `object` and `type` and to use it to define > > > interface

Re: [Python-ideas] More alternate constructors for builtin type

2019-05-07 Thread Steven D'Aprano
On Wed, May 08, 2019 at 12:18:34AM +1200, Greg Ewing wrote: > Steven D'Aprano wrote: > > >That suggests a possible pair of constructors: > > > >bytes.from_int(n) -> equivalent to b'%d' % n > >bytes.ord(n) -> equivalent to bytes((n,)) > > I don't see how bytes.from_int(n) is any

Re: [Python-ideas] More alternate constructors for builtin type

2019-05-07 Thread Greg Ewing
Steven D'Aprano wrote: That suggests a possible pair of constructors: bytes.from_int(n) -> equivalent to b'%d' % n bytes.ord(n) -> equivalent to bytes((n,)) I don't see how bytes.from_int(n) is any clearer about what it does than just bytes(n). If we're going to have named

Re: [Python-ideas] More alternate constructors for builtin type

2019-05-07 Thread Steven D'Aprano
On Tue, May 07, 2019 at 12:57:49AM +, Josh Rosenberg wrote: > bytes.ord is a bad name, given the behavior would be the opposite of ord > (ord converts length one str to int, not int to length one str). D'oh! I mean, well done, that was a test and you passed! *wink* Sorry for the