Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-26 Thread Collin Winter
On 4/22/06, Greg Ewing <[EMAIL PROTECTED]> wrote: > This is worth thinking about. Recently when pondering the > question of when it would or would not be appropriate to > put in type assertions to help catch bugs, I concluded > that it makes the most sense to do so when building a > data structure,

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-23 Thread Jim Jewett
On 4/21/06, Giovanni Bajo <[EMAIL PROTECTED]> wrote: > Another (similar) way would be to let the user pay for the high typechecking > price in normal cases *but* provide a list[int] class, which is a list > decorated with typechecks on modification operations. We could have > list[int|float]() to

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-22 Thread Bill Birch
On Sat, 22 Apr 2006 06:39 pm, Guido van Rossum wrote: ... > > No. This is the kind of thing that would very quickly turn "optional" > typing into *mandatory* typing. One library package adds type > declarations. Now all packages that use it are required to either add > type declarations or explicit

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-22 Thread Bill Birch
On Sat, 22 Apr 2006 03:12 am, Jim Jewett wrote: > On 4/20/06, Birch, Bill <[EMAIL PROTECTED]> wrote: > > Type comparison operators would only need a deep > > inspection of the types when the godel strings don't match. > > If most comparisons will be an exact match (not a subtype) > > the lookup sho

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-22 Thread Bill Birch
> Guido van Rossum wrote: > If I have some utterly dynamic > code that comes up with a list of a million ints, and then I pass > that > as an argument to a function that requests the argument type is > list[int], > > you wrap it in something that checks elements for intness > as you access

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-22 Thread Guido van Rossum
On 4/22/06, Talin <[EMAIL PROTECTED]> wrote: > Greg Ewing canterbury.ac.nz> writes: > > > Giovanni Bajo wrote: > > > > > Another (similar) way would be to let the user pay for the high > > > typechecking > > > price in normal cases *but* provide a list[int] class, which is a list > > > decorated

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread Talin
Greg Ewing canterbury.ac.nz> writes: > Giovanni Bajo wrote: > > > Another (similar) way would be to let the user pay for the high typechecking > > price in normal cases *but* provide a list[int] class, which is a list > > decorated with typechecks on modification operations. We could have > > li

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread Greg Ewing
Giovanni Bajo wrote: > Another (similar) way would be to let the user pay for the high typechecking > price in normal cases *but* provide a list[int] class, which is a list > decorated with typechecks on modification operations. We could have > list[int|float]() to construct a list which can hold

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread skip
Giovanni> One way would be to keep boolean flags like "is this a list of Giovanni> integers". It could be updated after each list modification, Giovanni> so that typechecks come for (almost) free. Where would that be done? If it's in the untyped function in Guido's example, how does

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread Giovanni Bajo
Guido van Rossum <[EMAIL PROTECTED]> wrote: > But let me point out that the key concern I have about the expense of > type checking is what would be done when unchecked code calls a > function with type-checked arguments. If I have some utterly dynamic > code that comes up with a list of a million

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread Ian Bicking
Guido van Rossum wrote: > This seems a good idea to remember when we get to that point. > > But let me point out that the key concern I have about the expense of > type checking is what would be done when unchecked code calls a > function with type-checked arguments. If I have some utterly dynamic

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread Jim Jewett
On 4/20/06, Birch, Bill <[EMAIL PROTECTED]> wrote: > Type comparison operators would only need a deep > inspection of the types when the godel strings don't match. > If most comparisons will be an exact match (not a subtype) > the lookup should be faster. If you're assuming that, then just checki

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread Edward Loper
On Apr 21, 2006, at 8:36 AM, Greg Ewing wrote: > Guido van Rossum wrote: >> If I have some utterly dynamic >> code that comes up with a list of a million ints, and then I pass >> that >> as an argument to a function that requests the argument type is >> list[int], > > you wrap it in something th

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread Michael Chermside
Building from Aahz's example, what you really want is a mechanism for typechecking that any accessed elements are ints when dynamic code generates a list of a million elements and passes it to a function declared to take a parameter of type "list[int]". And then make sure the following two examples

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread Aahz
On Sat, Apr 22, 2006, Greg Ewing wrote: > Guido van Rossum wrote: >> >> If I have some utterly dynamic code that comes up with a list of a >> million ints, and then I pass that as an argument to a function that >> requests the argument type is list[int], > > you wrap it in something that checks ele

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread Guido van Rossum
On 4/21/06, Greg Ewing <[EMAIL PROTECTED]> wrote: > Guido van Rossum wrote: > > If I have some utterly dynamic > > code that comes up with a list of a million ints, and then I pass that > > as an argument to a function that requests the argument type is > > list[int], > > you wrap it in something t

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread Greg Ewing
Guido van Rossum wrote: > If I have some utterly dynamic > code that comes up with a list of a million ints, and then I pass that > as an argument to a function that requests the argument type is > list[int], you wrap it in something that checks elements for intness as you access them. It'll still

Re: [Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread Guido van Rossum
This seems a good idea to remember when we get to that point. But let me point out that the key concern I have about the expense of type checking is what would be done when unchecked code calls a function with type-checked arguments. If I have some utterly dynamic code that comes up with a list of

[Python-3000] Type Comparisons with Godel Numbers

2006-04-21 Thread Birch, Bill
With reference to the last Gfdl blog on type checking (http://www.artima.com/weblogs/viewpost.jsp?thread=87182). There is concern that type comparison at runtime using objects will be quite expensive, so this posting is about optimisation. An idea is to compute a single canonical string which su