[IronPython] Generics support in IronPython
jimhug at microsoft.com
Sat Apr 2 03:17:30 CEST 2005
Martin Smith wrote:
> Will IronPython support generics?
Here's the short answer to your question:
>>> from System.Collections.Generic import *
>>> l = List[str]()
System.Exception: bad args to this method <method# Add on
This works today and creates a List<String>. All of the methods have
the right signatures and will be dynamically checked like any other CLR
library code called from Python. The syntax is the same as Guido
proposed in his blog entry on optional static types here:
There are still many open design questions about how generics and a
dynamic language can best work together, but most of the obvious things
just work in IronPython today. This is easy on the CLR because all of
the information about generic type instantiations is kept at runtime so
the standard reflective type inspection work just does the right thing.
> Also, is support for calling python code from other CLR languages
> 1.0? It would be a particularly useful to be able to call compiled
> code from C#, or, even better, extend python classes in C#.
Absolutely. You can already do some of this today where code that
expects a delegate can be passed a Python function which will look just
like a delegate to the C#/VB/etc programmer. The next level is to
provide some sort of static compilation to a .dll or .exe and that's
clearly on the 1.0 todo list, but not something you should expect
Extending a Python class in C# is an interesting challenge, and that
might be outside of the scope of 1.0. BTW - extending C# classes in
Python is something that works pretty well today and will only get
better. I'm not sure how much of a Python class's dynamic nature you'd
have to give up in order to make extending it from C# a sensible thing
to do. This one will need some more thought.
> Keep up the great work. I'm looking forward to the day I can write
> applications in python!
I look forward to that day as well. I don't think it's that far off
Thanks - Jim
More information about the Ironpython-users