Merge lp:~javier.collado/checkbox-core/staticmethods into lp:checkbox-core

Proposed by Javier Collado
Status: Merged
Merged at revision: 15
Proposed branch: lp:~javier.collado/checkbox-core/staticmethods
Merge into: lp:checkbox-core
Diff against target: 112 lines (+18/-18)
4 files modified
checkbox/journal/multi.py (+8/-8)
checkbox/message/signal.py (+2/-2)
checkbox/process/args.py (+6/-6)
checkbox/process/env.py (+2/-2)
To merge this branch: bzr merge lp:~javier.collado/checkbox-core/staticmethods
Reviewer Review Type Date Requested Status
Marc Tardif Approve
Review via email: mp+103279@code.launchpad.net

Description of the change

Those class methods that didn't actually used the cls parameter, have been changed to be static methods.

To post a comment you must log in.
Revision history for this message
Marc Tardif (cr3) wrote :

This is definately in the right direction where I would eventually like to see class methods replaced with static methods, and static methods replaced by functions. This would be consistent with what Guido said [1]: Ironically, there are now no known uses for class methods in the Python distribution (other than in the test suite). I might even get rid of classmethod in a future release if no good use for it can be found!

However, these changes should not be done systematically; if a class method doesn't happen to use the class argument, that doesn't necessarily mean it makes sense to make it a function. So, some class methods might make more sense to be expressed as just methods whereas others as functions.

1. http://www.python.org/download/releases/2.2/descrintro/

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'checkbox/journal/multi.py'
2--- checkbox/journal/multi.py 2012-04-23 19:36:19 +0000
3+++ checkbox/journal/multi.py 2012-04-24 13:33:32 +0000
4@@ -54,8 +54,8 @@
5
6 class Multi:
7
8- @classmethod
9- def truncateFilenames(cls, filenames):
10+ @staticmethod
11+ def truncateFilenames(filenames):
12 """Static method to truncate the given journal files to zero length."""
13 for filename in filenames:
14 if os.acess(filename, os.F_OK):
15@@ -67,8 +67,8 @@
16 if fd_close(fd) == -1:
17 logging.info("Can't close %s", filename)
18
19- @classmethod
20- def filenameToLogicalLines(cls, filename):
21+ @staticmethod
22+ def filenameToLogicalLines(filename):
23 """Static method to read the specified file, break it into lines,
24 and combine them into logical lines.
25
26@@ -171,8 +171,8 @@
27
28 return journal
29
30- @classmethod
31- def loadFilenamesFromStoreSubmitFilename(cls, submit_filename, directory):
32+ @staticmethod
33+ def loadFilenamesFromStoreSubmitFilename(submit_filename, directory):
34 """ Gets the journal files from a stored submit file.
35
36 :param submit_filename: The submit file name.
37@@ -293,8 +293,8 @@
38
39 return list(values)
40
41- @classmethod
42- def _getParamFromSubmitLine(cls, line, param):
43+ @staticmethod
44+ def _getParamFromSubmitLine(line, param):
45 lexer = Lexer(line)
46 token = Token()
47
48
49=== modified file 'checkbox/message/signal.py'
50--- checkbox/message/signal.py 2012-04-23 19:36:19 +0000
51+++ checkbox/message/signal.py 2012-04-24 13:33:32 +0000
52@@ -29,8 +29,8 @@
53
54 class Signal:
55
56- @classmethod
57- def find(cls, record, name, default=-1):
58+ @staticmethod
59+ def find(record, name, default=-1):
60 if not record:
61 return -1
62
63
64=== modified file 'checkbox/process/args.py'
65--- checkbox/process/args.py 2012-04-23 19:36:19 +0000
66+++ checkbox/process/args.py 2012-04-24 13:33:32 +0000
67@@ -50,8 +50,8 @@
68 else:
69 return True
70
71- @classmethod
72- def quotedToRaw(cls, quoted):
73+ @staticmethod
74+ def quotedToRaw(quoted):
75 if not quoted:
76 return True
77
78@@ -98,8 +98,8 @@
79
80 return raw
81
82- @classmethod
83- def argToRaw(cls, arg, raw=""):
84+ @staticmethod
85+ def argToRaw(arg, raw=""):
86 if raw:
87 raw += " "
88
89@@ -136,8 +136,8 @@
90
91 return raw
92
93- @classmethod
94- def splitRaw(cls, raw, args):
95+ @staticmethod
96+ def splitRaw(raw, args):
97 if not raw:
98 return True
99
100
101=== modified file 'checkbox/process/env.py'
102--- checkbox/process/env.py 2012-04-23 19:36:19 +0000
103+++ checkbox/process/env.py 2012-04-24 13:33:32 +0000
104@@ -93,6 +93,6 @@
105 else:
106 return True
107
108- @classmethod
109- def quotedToRaw(cls, quoted):
110+ @staticmethod
111+ def quotedToRaw(quoted):
112 return Args.quotedToRaw(quoted)

Subscribers

People subscribed via source and target branches

to all changes: