| Conditions | 6 |
| Total Lines | 63 |
| 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 namedtuple |
||
| 145 | @classmethod |
||
| 146 | def from_metadata(cls, doccomment, docstyle_definition, |
||
| 147 | marker, indent, range): |
||
| 148 | r""" |
||
| 149 | Assembles a list of parsed documentation comments. |
||
| 150 | |||
| 151 | This function just assembles the documentation comment |
||
| 152 | itself, without the markers and indentation. |
||
| 153 | |||
| 154 | >>> from coalib.bearlib.languages.documentation.DocumentationComment \ |
||
| 155 | ... import DocumentationComment |
||
| 156 | >>> from coalib.bearlib.languages.documentation.DocstyleDefinition \ |
||
| 157 | ... import DocstyleDefinition |
||
| 158 | >>> from coalib.results.TextRange import TextRange |
||
| 159 | >>> Description = DocumentationComment.Description |
||
| 160 | >>> Parameter = DocumentationComment.Parameter |
||
| 161 | >>> python_default = DocstyleDefinition.load("python3", "default") |
||
| 162 | >>> parsed_doc = [Description(desc='\nDescription\n'), |
||
| 163 | ... Parameter(name='age', desc='Age\n')] |
||
| 164 | >>> str(DocumentationComment.from_metadata( |
||
| 165 | ... parsed_doc, python_default, |
||
| 166 | ... python_default.markers[0], 4, |
||
| 167 | ... TextRange.from_values(0, 0, 0, 0))) |
||
| 168 | '\nDescription\n:param age:Age\n' |
||
| 169 | |||
| 170 | :param doccomment: |
||
| 171 | The list of parsed documentation comments. |
||
| 172 | :param docstyle_definition: |
||
| 173 | The ``DocstyleDefinition`` instance that defines what docstyle is |
||
| 174 | being used in a documentation comment. |
||
| 175 | :param marker: |
||
| 176 | The markers to be used in the documentation comment. |
||
| 177 | :param indent: |
||
| 178 | The indentation to be used in the documentation comment. |
||
| 179 | :param range: |
||
| 180 | The range of the documentation comment. |
||
| 181 | |||
| 182 | :return: |
||
| 183 | A ``DocumentationComment`` instance of the assembled documentation. |
||
| 184 | """ |
||
| 185 | assembled_doc = "" |
||
| 186 | for section in doccomment: |
||
| 187 | section_desc = section.desc.splitlines(keepends=True) |
||
| 188 | |||
| 189 | if isinstance(section, cls.Description): |
||
| 190 | assembled_doc += section_desc[0] |
||
| 191 | |||
| 192 | elif isinstance(section, cls.Parameter): |
||
| 193 | assembled_doc += (docstyle_definition.metadata.param_start + |
||
| 194 | section.name + |
||
| 195 | docstyle_definition.metadata.param_end + |
||
| 196 | section_desc[0]) |
||
| 197 | |||
| 198 | else: |
||
| 199 | assert isinstance(section, cls.ReturnValue) |
||
| 200 | assembled_doc += docstyle_definition.metadata.return_sep + \ |
||
| 201 | section_desc[0] |
||
| 202 | |||
| 203 | for desc in section_desc[1:]: |
||
| 204 | assembled_doc += desc |
||
| 205 | |||
| 206 | return DocumentationComment(assembled_doc, docstyle_definition, indent, |
||
| 207 | marker, range) |
||
| 208 | |||
| 222 |