def test_self_referencing_interface(self): class TreeNode(Interface): pass TreeNode.add_attribute('left', optional(TreeNode)) TreeNode.add_attribute('right', optional(TreeNode)) class TreeNodeImplementation: def __init__(self): self.left = None self.right = None tree = TreeNodeImplementation() tree.left = TreeNodeImplementation() tree.right = TreeNodeImplementation() self.assertIsInstance(tree, TreeNode) tree.left = 1 self.assertNotIsInstance(tree, TreeNode)
def test_optional(self): self.assertIsInstance(1, optional(int)) self.assertIsInstance(None, optional(int)) self.assertNotIsInstance('string', optional(int))
def test(a: optional(int)): return a