Is this function attribute weirdness a feature or bug?

Roy Katz katz at
Sat Aug 18 05:08:18 CEST 2001


I am using Python 2.2a1.  This works ok:

  def f(): pass
  f.att = 3


  class C:
      def g(): pass

  C.g.att = 3

   Traceback (most recent call last):
     File "<stdin>", line 1, in ?
   TypeError: read-only attribute: att

I get the same for instances.  Now,  when I attach 'f' to C, I again
get an error:

  C.f = f
  C.f.att2 = 3

  <same exception here>

However, I can still assign attributes to global f(): 

  f.att2 = 4
  print C.f.att2   # prints '4'

So is this a design feature or a bug? 



More information about the Python-list mailing list