[IronPython] (MS/Beta2) System.Collections.Generic.List bug?

Jim Hugunin jimhug at exchange.microsoft.com
Wed Apr 20 00:31:02 CEST 2005


Keith J. Farmer wrote:
> [Incidentally, the ".NET" in the version info is hardcoded -- is there
a
> means to pick up the full name of the environment, rather than just
the
> version?  This would allow more accurate reporting between MS and 3rd
> party CLR implementations.]

We're using System.Environment.Version to get the version number.  I
don't know any way to get a string specifying the implementation.  I'll
ask around and see what I can find.

> IronPython 0.7.2 on .NET 2.0.50215.44
> Copyright (c) Microsoft Corporation. All rights reserved.
> >>> from System.Collections.Generic import List
> >>> list = List[str]
> >>> list
> <type 'System.Collections.Generic.List`1[[System.String, mscorlib,
> Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'>
> >>> list.Add("abc")
> System.Exception: bad args to this method <method# Add on
> System.Collections.Generic.List`1[[System.String, mscorlib,

I also always make this mistake when using generics in IronPython.  It's
so common it might indicate we need to think about tweaking the design.
At the very least we should work on the error message.

List[str] returns a new type object List<String>.  When you print it
above you can see that it's a type rather than an instance.  You're
treating this like it's an instance of a list.  You need to make an
instance first:
>>> l = list()
>>> l.Add('hi')
>>> l.Add(2)
System.Exception: bad args to this method <method# Add on <snip>

Ordinarily you'll do this all as one call, i.e. "l = List[str]()".

In case you're unfamiliar with Python's unbound methods, these are
instance methods exposed on the class that you can call with an instance
as the first argument, i.e.
>>> list.Add(l, 'bye')

This is a part of Python's object model that we're trying to reflect
accurately in the .NET world.

I hope this answers your question - Jim



More information about the Ironpython-users mailing list