I have a descriptor
class ReferredItem():
def __init__(self, method):
self.method = method
def __get__(self, obj, objtype):
...
I use it as decorator:
class MyClass():
@ReferredItem
some_method(self):
...
I've seen the decorators are lower case. But classes should be named in camel case.
Should i name the class like referred_item
? Or leave it as it is now?
PEP8 states that
Almost without exception, class names use the CapWords convention.
without explaining what the exceptions are, but in the standard library, classes that are most commonly used as functions usually follow the function naming convention. E.g. itertools.groupby
is actually a class, but you don't notice that in ordinary usage; it's an implementation detail and groupby
could be rewritten as an actual function.
You can adopt a similar style by using the all-lowercase decorator naming convention for classes used as decorators: referred_item
, not ReferredItem
.
I usually use CamelCase for the class and then add an alias which I use as decorator.
referred_item = ReferredItem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With