Just out of curiosity - how would you feel if we enabled the behavior but issued a warning when it occurred? In v1.0 when we made this decision we had no warning support and it could serve as a mitigating factor in enabling it. But it could also be too noisy.
It's funny, I just got had to fix a bug in IronPython where they allow this but it doesn't really work. Given: List<SomeValueType> x; X[0].Bar = 42; fails to update the list. > -----Original Message----- > From: [email protected] [mailto:users- > [email protected]] On Behalf Of Count László de Almásy > Sent: Monday, August 10, 2009 5:20 PM > To: Discussion of IronPython > Subject: Re: [IronPython] ValueError: cannot assign to value types > > i dunno. i think this behavior needs to be re-thought for Ipy 2.6. i > understand the reasons behind the decision, but the bottom line is > that i'm unable to work with a perfectly valid, legal .NET assembly. > it's one thing to do this as the default behavior, but to not allow > the programmer to override it if that is his choice is not correct in > my opinion. > > On Fri, Aug 7, 2009 at 11:04 PM, Curt Hagenlocher<[email protected]> > wrote: > > __setattr__ it's not a *CLR*-level instance method of the type. > IronPython > > just makes it look like it is. > > One possibility is to simply create an entirely new Parcel from > scratch, > > assigning values as appropriate. For example, given the following C# > > classes: > > > > public struct Point { > > public int x, y; > > } > > public class Line { > > public Point to, from; > > } > > > > You can do this from Python: > > > > F:\tcwb\libs>ipy.exe > > IronPython 2.6 Beta 2 (2.6.0.20) on .NET 2.0.50727.4927 > > Type "help", "copyright", "credits" or "license" for more information. > >>>> import clr > >>>> clr.AddReference('x') > >>>> import Point, Line > >>>> l = Line() > >>>> l.to.x > > 0 > >>>> l.to.x = 1 > > Traceback (most recent call last): > > File "<stdin>", line 1, in <module> > > ValueError: cannot assign to value types > >>>> l.to = Point(x = 1, y = 2) > >>>> l.to.x > > 1 > >>>> > > > > On Fri, Aug 7, 2009 at 8:40 PM, Count László de Almásy > <[email protected]> > > wrote: > >> > >> i'm really stuck trying to change values for an object of type > >> 'Parcel', which comes from the openmetaverse library i'm using. how > >> this library is implemented i don't have control over, but the given > >> interface is to make local changes to these Parcel objects, then use > >> its Update() method to commit the changes. but it seems in > IronPython > >> i can't change these objects. > >> > >> >>> type(props) > >> <type 'Parcel'> > >> > >> >>> props.Name = "Yes" > >> Traceback (most recent call last): > >> File "<stdin>", line 1, in <module> > >> ValueError: cannot assign to value types > >> > >> after hours of struggling, i found > >> http://ironpython.codeplex.com/Wiki/View.aspx?title=Value%20Types > >> which seems to explain why i'm being bit here. bit it also says > >> "updates are still possible via instance methods on the value type > >> itself." so isn't "__setattr__" an instance method? seems i'm not > able > >> to use that either: > >> > >> >>> props.__setattr__("Name", "Yes") > >> Traceback (most recent call last): > >> File "<stdin>", line 1, in <module> > >> ValueError: Attempt to update field 'Name' on value type 'Parcel'; > >> value type fields cannot be directly modified > >> > >> ok, so what are my options? how do i get around this? i *have* to be > >> able to update objects of this type somehow. > >> > >> i can create a new object of that type, but the constructor doesn't > >> allow me to pre-stock it with values ( since i guess it assumes i'll > >> be able to change them later), and then of course once it's created > i > >> can't change anything. > >> > >> -- > >> Cheers, László > >> _______________________________________________ > >> Users mailing list > >> [email protected] > >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > _______________________________________________ > > Users mailing list > > [email protected] > > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > > > > > > -- > Cheers, László > _______________________________________________ > Users mailing list > [email protected] > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list [email protected] http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
