commit 39e10eed903c1920a50a175803726035b8448712 Author: Damian Johnson atagar@torproject.org Date: Sat Oct 8 14:03:08 2011 -0700
Using Pascal Case styling (unscores) for variables
According to PEP8 [1] both functions and variable names should use the underscore naming convention (ie, 'my_var') rather than camel case ('myVar'). This is a little weird for me and python standard libraries use both, but I see a readability advantage to this for functions and my previous approach of using camel case just for variables is kinda weird. Hence switching to the 'right' convention while the codebase is still tiny.
As an added bonus this conforms with torctl...
[1] http://www.python.org/dev/peps/pep-0008/ --- stem/types.py | 24 ++++++++++++------------ test/unit/version.py | 12 ++++++------ 2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/stem/types.py b/stem/types.py index 0f7030b..58845fe 100644 --- a/stem/types.py +++ b/stem/types.py @@ -55,23 +55,23 @@ class Version: raise ValueError("types.Version can only be compared with other Version instances")
for attr in ("major", "minor", "micro", "patch"): - myVersion = max(0, self.__dict__[attr]) - otherVersion = max(0, other.__dict__[attr]) + my_version = max(0, self.__dict__[attr]) + other_version = max(0, other.__dict__[attr])
- if myVersion > otherVersion: return 1 - elif myVersion < otherVersion: return -1 + if my_version > other_version: return 1 + elif my_version < other_version: return -1
- myStatus = self.status if self.status else "" - otherStatus = other.status if other.status else "" + my_status = self.status if self.status else "" + other_status = other.status if other.status else ""
- return cmp(myStatus, otherStatus) + return cmp(my_status, other_status)
-def get_version(versionStr): +def get_version(version_str): """ Parses a version string, providing back a types.Version instance.
Arguments: - versionStr (str) - string representing a tor version (ex. "0.2.2.23-alpha") + version_str (str) - representation of a tor version (ex. "0.2.2.23-alpha")
Returns: types.Version instance @@ -80,10 +80,10 @@ def get_version(versionStr): ValueError if input isn't a valid tor version """
- if not isinstance(versionStr, str): + if not isinstance(version_str, str): raise ValueError("argument is not a string")
- m = re.match(r'^([0-9]+).([0-9]+).([0-9]+)(.[0-9]+)?(-\S*)?$', versionStr) + m = re.match(r'^([0-9]+).([0-9]+).([0-9]+)(.[0-9]+)?(-\S*)?$', version_str)
if m: major, minor, micro, patch, status = m.groups() @@ -95,5 +95,5 @@ def get_version(versionStr): if status: status = status[1:]
return Version(int(major), int(minor), int(micro), patch, status) - else: raise ValueError("'%s' isn't a properly formatted tor version" % versionStr) + else: raise ValueError("'%s' isn't a properly formatted tor version" % version_str)
diff --git a/test/unit/version.py b/test/unit/version.py index fd32886..f241a8c 100644 --- a/test/unit/version.py +++ b/test/unit/version.py @@ -91,24 +91,24 @@ class TestVerionFunctions(unittest.TestCase): self.assertEqual(version.patch, patch) self.assertEqual(version.status, status)
- def assert_version_is_greater(self, firstVersion, secondVersion): + def assert_version_is_greater(self, first_version, second_version): """ Asserts that the parsed version of the first version is greate than the second (also checking the inverse). """
- version1 = stem.types.get_version(firstVersion) - version2 = stem.types.get_version(secondVersion) + version1 = stem.types.get_version(first_version) + version2 = stem.types.get_version(second_version) self.assertEqual(version1 > version2, True) self.assertEqual(version1 < version2, False)
- def assert_version_is_equal(self, firstVersion, secondVersion): + def assert_version_is_equal(self, first_version, second_version): """ Asserts that the parsed version of the first version equals the second. """
- version1 = stem.types.get_version(firstVersion) - version2 = stem.types.get_version(secondVersion) + version1 = stem.types.get_version(first_version) + version2 = stem.types.get_version(second_version) self.assertEqual(version1, version2)
def assert_string_matches(self, version):
tor-commits@lists.torproject.org