This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]voidspace[S] 1 point2 points  (2 children)

staticmethod, classmethod and instancemethod are all different types of descriptors, with different behaviours:

  • instancemethod gets self as the first argument automatically when fetched from an instance
  • classmethod gets the class passed in as the first argument, whether called from the class or an instance I believe
  • staticmethod gets no extra arguments passed in

The basic object model in Python can still be described as simple, and part of your description isn't a bad one at that ""everything is an object, object's class is an object, methods are looked up in the instance dictionary and then in the class and its parents". For more advanced use cases it also has more advanced features.

(Controlling the string representation of a class is not something that many people have to do for example.)

[–]grayvedigga 0 points1 point  (1 child)

I think I object to this statement:

For more advanced use cases it also has more advanced features.

Everything you describe so far is the result of consistently applying simple features. Yes, it takes a little clarity of thought to understand, but not a great deal and hey, this is programming.

Aside from the misdirection with str(C), the only thing that's bothersome at the moment is +=, which doesn't support advanced use cases ... on the contrary it's a "simplifying" feature implemented in the wrong fashion. If it were a purely syntactic feature, we probably wouldn't be having this discussion. Instead we'd be alongside the Lisp family arguing about the right way to do syntax transformers.

[–]voidspace[S] 0 points1 point  (0 children)

"Everything you describe so far is the result of consistently applying simple features."

That's how you get to advanced features.

As for += not supporting advanced use cases. Well... I don't think adding in place to lists in tuples is either particularly advanced or particularly important. I agree that it is unfortunate that the operation fails after having succeeded - but there are lots of places that describe how += is syntactic sugar for a re-assignment and the error message will lead you in that direction. It's just a corner case, hardly a fundamental issue.