Utility Classes :: Class

Overview

Let's say you have a situation like this:

class ClassA:
	@accepts(Self(), ClassB)
	def foo(self, b):
		...
		
class ClassB:
	@accepts(Self(), ClassA)
	def bar(self, a):
		...

See the problem? You can't use ClassB in the signature for ClassA.foo because it hasn't been declared yet. Sure, you could reverse the order of the class declarations, but then you'd have the same problem with ClassB.bar. The solution: the Class() utility class.

ClassB = Class("ClassB")
				
class ClassA:
	@accepts(Self(), ClassB)
	def foo(self, b):
		...
		
class ClassB:
	@accepts(Self(), ClassA)
	def bar(self, a):
		...

The Class() utility class allows deferring the lookup of the named class until it's actually needed for typechecking. Note the idiom used above: assign the Class() instance to a variable with the same name as the desired class. This is much cleaner than inlining the call to Class().

Details

Valid XHTML 1.0 Transitional