jtm
jtm

Reputation: 1575

Property decorator

I have a property decorator so:

def Property(f):  
    """
    Allow readable properties without voodoo.
    """
    fget, fset, fdel = f()
    fdoc = f.__doc__
    return property(fget, fset, fdel, fdoc)

Used (for example) so:

    @Property
    def method():
        """"""
        def fget(self):
            return some expression...
        return fget, None, None

So my question is about the python way of doing this. Pydev complains about

"method method should have self as first parameter"

And pylint gives me

Method has no argument

I know I can turn off this error message in pydev, but Im wondering if there is a better way to manage methods that do not take self as a parameter, something I can do better.

Upvotes: 2

Views: 3174

Answers (1)

Zach Kelling
Zach Kelling

Reputation: 53819

You could use @staticmethod to create a method which does not receive an implicit first argument. Doesn't Python's @property decorator already do what you want?

class Foo(object):
    @property
    def bar(self):
        return 'foobar'

>>> foo = Foo()

>>> foo.bar
<<< 'foobar'

Upvotes: 10

Related Questions