text: Q:
  
  Class objects are irregular when assigning functions
  
  Let's say I have a function like this:
  
  def id(x):
    return x
  
  I expect to be able to bind it to any object (let's say x),
  
  x.f = id
  
  and be able to do
  
  x.f(1)
  => 1
  
  However, classes are not regular objects because it does not work :
  
  class X(object):
    pass
  
  X.f = id
  x.f(1)
  => unbound method f() must be called with X instance as first argument (got int instance instead)
  
  So that I have to do,
  
  X.f=staticmethod(id)
  X.f(1)
  => 1
  
  However it doesn't work with regular objects,
  
  x.f=staticmethod(f)
  x.f(1)
  => 'staticmethod' object is not callable
  
  So is there a way to have assignment work as expected in generic code where
  I do not know whether the object assigned to is a regular object of a class object
  and when the assigned object may be a function?
  
  A:
  
  import inspect
  if inspect.isclass(X):
     X.f = staticmethod(f)
  else:
     X.f = f
  
  The issue isn't the assignment; that works fine. It is that functions on classes take self as their first parameter, and your function doesn't. You can get the actual function back with 
  X.__dict__['f']
  <function f at 0x023A52F0>
  
  or
  X.f
  <unbound method X.f>
  X.f.im_func
  <function f at 0x023A52F0>
  
  (You are getting an unbound method instead of the original function, because in Python 2.x that is what happens when you access a method on a class. In Python 3.x that is changed and you just get the original function. I believe it is for backwards compatibility with old-style classes.)
  
  This is a weird thing to want to do: you are working at a very high level of abstraction if you don't even know if the object you are working with is a class or not! For that matter, what if you get passed a built-in type, say a string? You can't set attributes on that! I think you need to work at a slightly lower level.
  
  