Conditions | 5 |
Total Lines | 52 |
Lines | 0 |
Ratio | 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 | import os.path |
||
104 | @classmethod |
||
105 | def load(cls, language, docstyle): |
||
106 | """ |
||
107 | Returns a `DocstyleDefinition` defined for the given language and |
||
108 | docstyle from the coala docstyle definition files. |
||
109 | |||
110 | The marker settings are loaded from the according coalang-files. Each |
||
111 | setting inside them are considered a marker setting. |
||
112 | |||
113 | :param language: The programming language. For example |
||
114 | `"CPP"` for C++ or `"PYTHON3"` for Python 3. |
||
115 | The given string is automatically lowered, |
||
116 | so passing i.e. "CPP" or "cpp" makes no |
||
117 | difference. |
||
118 | :param docstyle: The documentation style/tool used. For |
||
119 | example `"default"` or `"doxygen"`. |
||
120 | The given string is automatically lowered, |
||
121 | so passing i.e. "default" or "DEFAULT" makes |
||
122 | no difference. |
||
123 | :raises FileNotFoundError: Raised when the given docstyle was not |
||
124 | found. This is a compatability exception |
||
125 | from `coalib.misc.Compatability` module. |
||
126 | :raises KeyError: Raised when the given language is not |
||
127 | defined for given docstyle. |
||
128 | :return: The `DocstyleDefinition` for giving language |
||
129 | and docstyle. |
||
130 | """ |
||
131 | |||
132 | docstyle = docstyle.lower() |
||
133 | |||
134 | language_config_parser = ConfParser(remove_empty_iter_elements=False) |
||
135 | try: |
||
136 | docstyle_settings = language_config_parser.parse( |
||
137 | os.path.dirname(__file__) + "/" + docstyle + ".coalang") |
||
138 | except FileNotFoundError as ex: |
||
139 | raise type(ex)("Docstyle definition " + repr(docstyle) + " not " |
||
140 | "found.") |
||
141 | |||
142 | language = language.lower() |
||
143 | |||
144 | try: |
||
145 | docstyle_settings = docstyle_settings[language] |
||
146 | except KeyError: |
||
147 | raise KeyError("Language {} is not defined for docstyle {}." |
||
148 | .format(repr(language), repr(docstyle))) |
||
149 | |||
150 | marker_sets = (tuple(value) |
||
151 | for key, value in |
||
152 | filter(lambda kv: not kv[0].startswith("comment"), |
||
153 | docstyle_settings.contents.items())) |
||
154 | |||
155 | return cls(language, docstyle, marker_sets) |
||
156 |