# expected behavior: def f(a,b): class X: c = a b = "foo" def g(self): return b return X print f(5,6).c # 5 print f(5,6)().g() # 6 print hasattr(f(5,6), 'a') # False print f(5,6).b # 'foo' # in the following example, 'a' and 'b' unexpectedly # show up in the class definition because of the call # to locals(), which a genuine class might want to do # e.g. to do some post-processing on the methods. # note in particular that the nested 'b' overrides # the class 'b' in the class definition, which is bad def f(a,b): class X: c = a b = "foo" def g(self): return b print locals() # {'a': 5, 'b': 6, 'c': 5, ...} return X print f(5,6).c # 5 print f(5,6)().g() # 6 print f(5,6).a # 5 -- unexpected print f(5,6).b # 6 -- really bad