Functions are objects like any other and there needs to be consistency on what happens when objects are assigned to names, regardless of where the names are (i.e. in local namespace or on as attributes on an object).
When you define a function with def
you are binding a function to the name after def
, and when you do assignment like some_object.f = my_function
you are also binding the function to a name. There's no magic in the assignment process that would change the nature of the function.
There is magic in the class definition process. Functions defined as instance methods (that is, functions defined inside a class definition) are not simply assigned as attributes to instances, but instead they are bound to the instance using a descriptor.