Conditions | 7 |
Total Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | 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:
1 | from collections import Iterable, namedtuple |
||
129 | @classmethod |
||
130 | @enforce_signature |
||
131 | def load(cls, language: str, docstyle: str, coalang_dir=None): |
||
132 | """ |
||
133 | Loads a ``DocstyleDefinition`` from the coala docstyle definition files. |
||
134 | |||
135 | This function considers all settings inside the according coalang-files |
||
136 | as markers, except ``param_start``, ``param_end`` and ``return_sep`` |
||
137 | which are considered as special metadata markers. |
||
138 | |||
139 | .. note:: |
||
140 | |||
141 | When placing new coala docstyle definition files, these must |
||
142 | consist of only lowercase letters and end with ``.coalang``! |
||
143 | |||
144 | :param language: The case insensitive programming language of |
||
145 | the documentation comment as a string. |
||
146 | :param docstyle: The case insensitive documentation |
||
147 | style/tool used to document code, e.g. |
||
148 | ``"default"`` or ``"doxygen"``. |
||
149 | :param coalang_dir: Path to directory with coalang docstyle |
||
150 | definition files. This replaces the default |
||
151 | path if given. |
||
152 | :raises FileNotFoundError: Raised when the given docstyle was not |
||
153 | found. |
||
154 | :raises KeyError: Raised when the given language is not |
||
155 | defined for given docstyle. |
||
156 | :return: The ``DocstyleDefinition`` for given language |
||
157 | and docstyle. |
||
158 | """ |
||
159 | |||
160 | docstyle = docstyle.lower() |
||
161 | |||
162 | language_config_parser = ConfParser(remove_empty_iter_elements=False) |
||
163 | |||
164 | coalang_file = os.path.join( |
||
165 | coalang_dir or os.path.dirname(__file__), docstyle + ".coalang") |
||
166 | |||
167 | try: |
||
168 | docstyle_settings = language_config_parser.parse(coalang_file) |
||
169 | except FileNotFoundError: |
||
170 | raise FileNotFoundError("Docstyle definition " + repr(docstyle) + |
||
171 | " not found.") |
||
172 | |||
173 | language = language.lower() |
||
174 | |||
175 | try: |
||
176 | docstyle_settings = docstyle_settings[language] |
||
177 | except KeyError: |
||
178 | raise KeyError("Language {!r} is not defined for docstyle {!r}." |
||
179 | .format(language, docstyle)) |
||
180 | |||
181 | metadata_settings = ("param_start", "param_end", "return_sep") |
||
182 | |||
183 | metadata = cls.Metadata(*(str(docstyle_settings.get(req_setting, "")) |
||
184 | for req_setting in metadata_settings)) |
||
185 | |||
186 | marker_sets = (tuple(value) |
||
187 | for key, value in |
||
188 | docstyle_settings.contents.items() |
||
189 | if key not in metadata_settings and |
||
190 | not key.startswith("comment")) |
||
191 | |||
192 | return cls(language, docstyle, marker_sets, metadata) |
||
193 | |||
211 |