Wild idea - a type finder

Stuart Reynolds S.I.Reynolds at cs.bham.ac.uk
Wed Nov 17 07:02:54 EST 1999

Does anyone know of any tools which let you do things like:

We have some exisiting function:

  def f(a, b):
      return a<b

And we want to reverse engineer its type from its implementation:

   findtype( f )

- function takes 2 args
- a and b need to be comparable
- returns a boolean (actually an int in Python)

So the type of f is:


Or in another example you might get:

  >>> findtype( add )

  >>> findtype( map )
( ()() ) denotes a function which takes two arguments of unknown type.

I've only ever seen this kind of thing in pure functional programming
languages (gopher to be specific).

The reason I ask is that I think, in general, its really useful to be
able to tell what minimum interface the arguments you give to a method
needs to support (you can stick it in your documenation for one thing).
It would also be pretty useful to uncover the kind of nasty bugs which
crop up in untyped langauges whereby the functions or methods you've
written have stronger requirements on the interfaces of their arguments
than you realised (espcially in the case where your code calls lots of
other functions who's types you're not too sure about).


More information about the Python-list mailing list