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