Conditions | 3 |
Total Lines | 57 |
Code Lines | 51 |
Lines | 57 |
Ratio | 100 % |
Changes | 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:
1 | #!/usr/bin/env python3 |
||
17 | View Code Duplication | def grab_args(): |
|
|
|||
18 | """ |
||
19 | Parse arguments from argparse/questionnaire. |
||
20 | |||
21 | Invoke a function with those arguments. |
||
22 | """ |
||
23 | if getattr(sys, "frozen", False) and len(sys.argv) == 1: |
||
24 | questionnaire() |
||
25 | else: |
||
26 | parser = argutils.default_parser("bb-tclnewprd", "Check for new PRDs for TCL devices") |
||
27 | parser.add_argument( |
||
28 | "prds", |
||
29 | help="Only scan space separated list of PRDs", |
||
30 | default=None, |
||
31 | nargs="*") |
||
32 | parser.add_argument( |
||
33 | "-f", |
||
34 | "--floor", |
||
35 | dest="floor", |
||
36 | help="When to start, default=1", |
||
37 | default=1, |
||
38 | type=int, |
||
39 | choices=range(0, 998), |
||
40 | metavar="INT") |
||
41 | parser.add_argument( |
||
42 | "-c", |
||
43 | "--ceiling", |
||
44 | dest="ceiling", |
||
45 | help="When to stop, default=60", |
||
46 | default=None, |
||
47 | type=int, |
||
48 | choices=range(1, 999), |
||
49 | metavar="INT") |
||
50 | parser.add_argument( |
||
51 | "-x", |
||
52 | "--export", |
||
53 | dest="export", |
||
54 | help="Write XML to logs folder", |
||
55 | action="store_true", |
||
56 | default=False) |
||
57 | parser.add_argument( |
||
58 | "-np", |
||
59 | "--no-prefix", |
||
60 | dest="noprefix", |
||
61 | help="Don't add PRD- prefix", |
||
62 | action="store_true", |
||
63 | default=False) |
||
64 | parser.add_argument( |
||
65 | "-k", |
||
66 | "--key2", |
||
67 | dest="key2mode", |
||
68 | help="Use KEY2 syntax", |
||
69 | action="store_true", |
||
70 | default=False) |
||
71 | args = parser.parse_args(sys.argv[1:]) |
||
72 | parser.set_defaults() |
||
73 | execute_args(args) |
||
74 | |||
147 |