Conditions | 13 |
Total Lines | 78 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like introduce_renamed_methods_qheaderview() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | def introduce_renamed_methods_qheaderview(QHeaderView): |
||
2 | |||
3 | _isClickable = QHeaderView.isClickable |
||
4 | def sectionsClickable(self): |
||
5 | """ |
||
6 | QHeaderView.sectionsClickable() -> bool |
||
7 | """ |
||
8 | return _isClickable(self) |
||
9 | QHeaderView.sectionsClickable = sectionsClickable |
||
10 | def isClickable(self): |
||
11 | raise Exception('isClickable is only available in Qt4. Use ' |
||
12 | 'sectionsClickable instead.') |
||
13 | QHeaderView.isClickable = isClickable |
||
14 | |||
15 | |||
16 | _isMovable = QHeaderView.isMovable |
||
17 | def sectionsMovable(self): |
||
18 | """ |
||
19 | QHeaderView.sectionsMovable() -> bool |
||
20 | """ |
||
21 | return _isMovable(self) |
||
22 | QHeaderView.sectionsMovable = sectionsMovable |
||
23 | def isMovable(self): |
||
24 | raise Exception('isMovable is only available in Qt4. Use ' |
||
25 | 'sectionsMovable instead.') |
||
26 | QHeaderView.isMovable = isMovable |
||
27 | |||
28 | |||
29 | _resizeMode = QHeaderView.resizeMode |
||
30 | def sectionResizeMode(self, logicalIndex): |
||
31 | """ |
||
32 | QHeaderView.sectionResizeMode(int) -> QHeaderView.ResizeMode |
||
33 | """ |
||
34 | return _resizeMode(self, logicalIndex) |
||
35 | QHeaderView.sectionResizeMode = sectionResizeMode |
||
36 | def resizeMode(self, logicalIndex): |
||
37 | raise Exception('resizeMode is only available in Qt4. Use ' |
||
38 | 'sectionResizeMode instead.') |
||
39 | QHeaderView.resizeMode = resizeMode |
||
40 | |||
41 | _setClickable = QHeaderView.setClickable |
||
42 | def setSectionsClickable(self, clickable): |
||
43 | """ |
||
44 | QHeaderView.setSectionsClickable(bool) |
||
45 | """ |
||
46 | return _setClickable(self, clickable) |
||
47 | QHeaderView.setSectionsClickable = setSectionsClickable |
||
48 | def setClickable(self, clickable): |
||
49 | raise Exception('setClickable is only available in Qt4. Use ' |
||
50 | 'setSectionsClickable instead.') |
||
51 | QHeaderView.setClickable = setClickable |
||
52 | |||
53 | |||
54 | _setMovable = QHeaderView.setMovable |
||
55 | def setSectionsMovable(self, movable): |
||
56 | """ |
||
57 | QHeaderView.setSectionsMovable(bool) |
||
58 | """ |
||
59 | return _setMovable(self, movable) |
||
60 | QHeaderView.setSectionsMovable = setSectionsMovable |
||
61 | def setMovable(self, movable): |
||
62 | raise Exception('setMovable is only available in Qt4. Use ' |
||
63 | 'setSectionsMovable instead.') |
||
64 | QHeaderView.setMovable = setMovable |
||
65 | |||
66 | |||
67 | _setResizeMode = QHeaderView.setResizeMode |
||
68 | def setSectionResizeMode(self, *args): |
||
69 | """ |
||
70 | QHeaderView.setSectionResizeMode(QHeaderView.ResizeMode) |
||
71 | QHeaderView.setSectionResizeMode(int, QHeaderView.ResizeMode) |
||
72 | """ |
||
73 | _setResizeMode(self, *args) |
||
74 | QHeaderView.setSectionResizeMode = setSectionResizeMode |
||
75 | def setResizeMode(self, *args): |
||
76 | raise Exception('setResizeMode is only available in Qt4. Use ' |
||
77 | 'setSectionResizeMode instead.') |
||
78 | QHeaderView.setResizeMode = setResizeMode |
||
79 | |||
83 |