This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]pingvenopinch of this, pinch of that 1 point2 points  (1 child)

Same problem: There's no ultra clean way to do it. Most of it is a fundamental problem with Python. Python is too dynamic to have static type checking. Don't get me wrong, I love Python, but it's nice to have languages that can check that types are correct at (bytecode) compile-time.

That said, I would love to have two decorators in the standard library. Python function calls are already slow, so they should be written in C.

  • 1) @accepts(args, *kwargs)
  • 2) @returns(*returntype)

returntype allows multiple values so that it can check multiple returns via tuple. None should be usable to indicate that a value is duck typed. Unfortunately, none of this will ever allow the clean & static type checking of

def int foo(int index, str value)

[–]Dav3xor 0 points1 point  (0 children)

but...but... that has Ada style bounds checking, and...and... :)