| Conditions | 2 |
| Total Lines | 71 |
| 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 |
||
| 137 | def test_extract_documentation_PYTHON3(self): |
||
| 138 | data = DocumentationExtractionTest.load_testdata(".py") |
||
| 139 | |||
| 140 | docstyle_PYTHON3_default = DocstyleDefinition.load("PYTHON3", |
||
| 141 | "default") |
||
| 142 | docstyle_PYTHON3_doxygen = DocstyleDefinition.load("PYTHON3", |
||
| 143 | "doxygen") |
||
| 144 | |||
| 145 | expected = (DocumentationComment( |
||
| 146 | ("\n" |
||
| 147 | "Module description.\n" |
||
| 148 | "\n" |
||
| 149 | "Some more foobar-like text.\n"), |
||
| 150 | docstyle_PYTHON3_default, |
||
| 151 | docstyle_PYTHON3_default.markers[0], |
||
| 152 | TextRange.from_values(1, 1, 5, 4)), |
||
| 153 | DocumentationComment( |
||
| 154 | ("\n" |
||
| 155 | "A nice and neat way of documenting code.\n" |
||
| 156 | ":param radius: The explosion radius.\n"), |
||
| 157 | docstyle_PYTHON3_default, |
||
| 158 | docstyle_PYTHON3_default.markers[0], |
||
| 159 | TextRange.from_values(8, 5, 11, 8)), |
||
| 160 | DocumentationComment( |
||
| 161 | ("\n" |
||
| 162 | "Docstring with layouted text.\n" |
||
| 163 | "\n" |
||
| 164 | " layouts inside docs are preserved for these " |
||
| 165 | "documentation styles.\n" |
||
| 166 | "this is intended.\n"), |
||
| 167 | docstyle_PYTHON3_default, |
||
| 168 | docstyle_PYTHON3_default.markers[0], |
||
| 169 | TextRange.from_values(14, 1, 19, 4)), |
||
| 170 | DocumentationComment( |
||
| 171 | (" Docstring directly besides triple quotes.\n" |
||
| 172 | " Continues here. "), |
||
| 173 | docstyle_PYTHON3_default, |
||
| 174 | docstyle_PYTHON3_default.markers[0], |
||
| 175 | TextRange.from_values(21, 1, 22, 24)), |
||
| 176 | DocumentationComment( |
||
| 177 | ("super\n" |
||
| 178 | " nicely\n" |
||
| 179 | "short"), |
||
| 180 | docstyle_PYTHON3_default, |
||
| 181 | docstyle_PYTHON3_default.markers[0], |
||
| 182 | TextRange.from_values(35, 1, 37, 9))) |
||
| 183 | |||
| 184 | self.assertEqual( |
||
| 185 | tuple(extract_documentation(data, "PYTHON3", "default")), |
||
| 186 | expected) |
||
| 187 | |||
| 188 | # Change only the docstyle in expected results. |
||
| 189 | expected = list(DocumentationComment(r.documentation, |
||
| 190 | docstyle_PYTHON3_doxygen, |
||
| 191 | r.marker, |
||
| 192 | r.range) |
||
| 193 | for r in expected) |
||
| 194 | |||
| 195 | expected.insert(4, DocumentationComment( |
||
| 196 | (" Alternate documentation style in doxygen.\n" |
||
| 197 | " Subtext\n" |
||
| 198 | " More subtext (not correctly aligned)\n" |
||
| 199 | " sub-sub-text\n" |
||
| 200 | "\n"), |
||
| 201 | docstyle_PYTHON3_doxygen, |
||
| 202 | docstyle_PYTHON3_doxygen.markers[1], |
||
| 203 | TextRange.from_values(25, 1, 29, 3))) |
||
| 204 | |||
| 205 | self.assertEqual( |
||
| 206 | list(extract_documentation(data, "PYTHON3", "doxygen")), |
||
| 207 | expected) |
||
| 208 | |||
| 212 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.