Olivia5k / piper

Build system that builds and very little more
http://thiderman.org/piper/
MIT License
5 stars 0 forks source link

Use properties instead of getter methods #10

Open daenney opened 9 years ago

daenney commented 9 years ago

I'd like to propose we switch a lot of the get_* methods to use properties instead. Since it's a property without a setter defined trying to set it will not work. In cases where we do need to be able to set it a method decorated with @<property>.setter can be declared allowing assignment.

This makes the code look and work more Pythonicly.

before

class GitVersion(Version):
    """
    Versioning based on the output of `git describe`

    """
[..]

    def get_version(self):
        cmd = 'git describe'

        if self.config['arguments']:
            cmd += ' ' + self.config['arguments']
        return oneshot(cmd)
version = GitVersion().get_version()

after

class GitVersion(Version):
    """
    Versioning based on the output of `git describe`

    """
[..]

    @property
    def version(self):
        cmd = 'git describe'

        if self.config['arguments']:
            cmd += ' ' + self.config['arguments']
        return oneshot(cmd)
version =  GitVersion().version
Olivia5k commented 9 years ago

:+1:, since it is clearer. Also :+1: for the word Pythonicly, haha.

daenney commented 9 years ago

Tacking on ly's to everything is half the fun!

Olivia5k commented 9 years ago

You obviously mean halfly the fun, right? :smiling_imp: