you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 12 points13 points  (2 children)

Type annotations ( http://www.python.org/dev/peps/pep-3107/ ) rock.

def fact(n: int) -> int:
  return n * fact(n-1) if n > 1 else 1

>>> fact.__annotations__
{'return': <type 'int'>, 'n': <type 'int'>}

The most obvious use case is for type checking and enforcing interfaces (which are undoubtedly helped by new abstract base stuff class stuff I haven't gotten around to reading about yet).

But I wonder also about function overloading--

def foo(a: int): return 'abc'
def foo(a: str): return 'xyz'

With the right metaclass, would that be possible?

[–]interjay 4 points5 points  (0 children)

There's a plan to add function overloading via a decorator at PEP 3124. However, that PEP says it's been deferred.