Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save shiroyuki/3138640 to your computer and use it in GitHub Desktop.

Select an option

Save shiroyuki/3138640 to your computer and use it in GitHub Desktop.
Example for Imagination's type validator
# This example works with the developmental build of Imagination
from imagination.decorator.validator import restrict_type
# One sad old way of validation
def old_say(context):
assert isinstance(context, unicode) or isinstance(context, str)
print context
# Example on a function
@restrict_type(unicode)
def new_say(context):
print context
class Person(object):
# Example on a constructor
@restrict_type(unicode, int)
def __init__(self, name, age):
self.name = name
self.age = age
self.__friends = []
# Example on an instance method
@restrict_type(Person)
def add_friend(self, person):
self.__friends.append(person)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment