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 | # -*- coding: utf-8 -*- |
||
2 | # |
||
3 | # Copyright © The Spyder Development Team |
||
4 | # |
||
5 | # Licensed under the terms of the MIT License |
||
6 | # (see LICENSE.txt for details) |
||
7 | |||
8 | def introduce_renamed_methods_qheaderview(QHeaderView): |
||
9 | |||
10 | _isClickable = QHeaderView.isClickable |
||
11 | def sectionsClickable(self): |
||
12 | """ |
||
13 | QHeaderView.sectionsClickable() -> bool |
||
14 | """ |
||
15 | return _isClickable(self) |
||
16 | QHeaderView.sectionsClickable = sectionsClickable |
||
17 | def isClickable(self): |
||
18 | raise Exception('isClickable is only available in Qt4. Use ' |
||
19 | 'sectionsClickable instead.') |
||
20 | QHeaderView.isClickable = isClickable |
||
21 | |||
22 | |||
23 | _isMovable = QHeaderView.isMovable |
||
24 | def sectionsMovable(self): |
||
25 | """ |
||
26 | QHeaderView.sectionsMovable() -> bool |
||
27 | """ |
||
28 | return _isMovable(self) |
||
29 | QHeaderView.sectionsMovable = sectionsMovable |
||
30 | def isMovable(self): |
||
31 | raise Exception('isMovable is only available in Qt4. Use ' |
||
32 | 'sectionsMovable instead.') |
||
33 | QHeaderView.isMovable = isMovable |
||
34 | |||
35 | |||
36 | _resizeMode = QHeaderView.resizeMode |
||
37 | def sectionResizeMode(self, logicalIndex): |
||
38 | """ |
||
39 | QHeaderView.sectionResizeMode(int) -> QHeaderView.ResizeMode |
||
40 | """ |
||
41 | return _resizeMode(self, logicalIndex) |
||
42 | QHeaderView.sectionResizeMode = sectionResizeMode |
||
43 | def resizeMode(self, logicalIndex): |
||
44 | raise Exception('resizeMode is only available in Qt4. Use ' |
||
45 | 'sectionResizeMode instead.') |
||
46 | QHeaderView.resizeMode = resizeMode |
||
47 | |||
48 | _setClickable = QHeaderView.setClickable |
||
49 | def setSectionsClickable(self, clickable): |
||
50 | """ |
||
51 | QHeaderView.setSectionsClickable(bool) |
||
52 | """ |
||
53 | return _setClickable(self, clickable) |
||
54 | QHeaderView.setSectionsClickable = setSectionsClickable |
||
55 | def setClickable(self, clickable): |
||
56 | raise Exception('setClickable is only available in Qt4. Use ' |
||
57 | 'setSectionsClickable instead.') |
||
58 | QHeaderView.setClickable = setClickable |
||
59 | |||
60 | |||
61 | _setMovable = QHeaderView.setMovable |
||
62 | def setSectionsMovable(self, movable): |
||
63 | """ |
||
64 | QHeaderView.setSectionsMovable(bool) |
||
65 | """ |
||
66 | return _setMovable(self, movable) |
||
67 | QHeaderView.setSectionsMovable = setSectionsMovable |
||
68 | def setMovable(self, movable): |
||
69 | raise Exception('setMovable is only available in Qt4. Use ' |
||
70 | 'setSectionsMovable instead.') |
||
71 | QHeaderView.setMovable = setMovable |
||
72 | |||
73 | |||
74 | _setResizeMode = QHeaderView.setResizeMode |
||
75 | def setSectionResizeMode(self, *args): |
||
76 | """ |
||
77 | QHeaderView.setSectionResizeMode(QHeaderView.ResizeMode) |
||
78 | QHeaderView.setSectionResizeMode(int, QHeaderView.ResizeMode) |
||
79 | """ |
||
90 |