News for hackers. Stuff that matters.
Re:Using attrs for everything in Python by weberc2 on Thursday August 25, 2016 @06:15PM (#12362915)
Is this safe in all cases? What about complex types? Specifically if you assign a variable to an element in the array, and then replace the element in the array? You'd have to take care not to update the value of the variable.
Re:Using attrs for everything in Python by Animats on Thursday August 25, 2016 @07:55PM (#12363378)
Assigning a variable to a destination declared to be an incompatible type should produce an error at compile time if possible, and at at run time otherwise. That's what type declarations are all about.
Re:Using attrs for everything in Python by weberc2 on Thursday August 25, 2016 @08:07PM (#12363431)
I think you misunderstand. Here's an example:

``` foos = [Foo(a=0), Foo(a=1)] f0 = foos[0] foos[0] = Foo(a=2)

print(f0.a) # 0 print(foos[0].a) # 2 ```

`foos` is a list of type `Foo`, but it still can't be safely made into a dense list (at least not naively).

Re:Using attrs for everything in Python by sanxiyn on Thursday August 25, 2016 @11:14PM (#12364055)
You are right. Array elements need to have value semantics to do complete unboxing. But for NumPy-like use cases, they do.

It should be noted that PyPy already does unboxing Animats suggested, without any type annotation. At least for 4 years. It is not theoretical. https://morepypy.blogspot.com/2011/10/more-compact-lists-wit...

Re:Using attrs for everything in Python by sevensor on Thursday August 25, 2016 @07:57PM (#12363389)
Python's arrays are already typed, and have been for long years. Python's lists may hold arbitrary objects and would be much harder to reason about in this context.