04.01.11 02:56, Guido van Rossum пише:
That said, I am sure there are use cases for static property and class property -- I've run into them myself.
An example use case for class property: in App Engine, we have a Model class (it's similar to Django's Model class). A model has a "kind" which is a string (it's the equivalent of an SQL table name). The kind is usually the class name but sometimes there's a need to override it. However once the class is defined it should be considered read-only. Currently our choices are to make this an instance property (but there are some situations where we don't have an instance, e.g. when creating a new instance using a class method); or to make it a class attribute (but this isn't read-only); or to make it a class method (which requires the user to write M.kind() instead of M.kind). If I had class properties I'd use one here.
Try to combine classmethod and property:
... @classmethod ... @property ... def name(cls): ... return cls.__name__ ...
And as you said, classmethod supersedes staticmethod. The only strong use case for staticmethod that I know is to make a Python function a class attribute without making it a method. And for static property there is no even such use case.