| Conditions | 3 |
| Total Lines | 54 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 | """ |
||
| 27 | @staticmethod |
||
| 28 | def export_for_english( # pylint: disable=too-many-locals |
||
| 29 | definition: BaseDefinition, |
||
| 30 | key: str, |
||
| 31 | style: str = DEFAULT_HTML_STYLE, |
||
| 32 | ) -> str: |
||
| 33 | # de = definition english |
||
| 34 | tags = { |
||
| 35 | "normal": [ |
||
| 36 | '<span class="dg">(%s)</span>', |
||
| 37 | '<span class="dt">[%s]</span> ', |
||
| 38 | ' <span class="db">%s</span>', |
||
| 39 | f'<span class="definition eng" id={definition.id}>%s</span>', |
||
| 40 | '<div class="d_line">%s</div>', |
||
| 41 | '<span class="w_name">%s</span>, ', |
||
| 42 | '<span class="w_origin"><%s></span> ', |
||
| 43 | ], |
||
| 44 | "ultra": [ |
||
| 45 | "(%s)", |
||
| 46 | "[%s] ", |
||
| 47 | " %s", |
||
| 48 | "<de>%s</de>", |
||
| 49 | "<ld>%s</ld>", |
||
| 50 | "<wn>%s</wn>, ", |
||
| 51 | "<o><%s></o> ", |
||
| 52 | ], |
||
| 53 | } |
||
| 54 | |||
| 55 | ( |
||
| 56 | t_d_gram, |
||
| 57 | t_d_tags, |
||
| 58 | t_d_body, |
||
| 59 | t_def, |
||
| 60 | t_def_line, |
||
| 61 | t_word_name, |
||
| 62 | t_word_origin, |
||
| 63 | ) = tags[style] |
||
| 64 | |||
| 65 | gram_form = str(definition.slots or "") + definition.grammar_code |
||
| 66 | def_gram = t_d_gram % gram_form if gram_form else "" |
||
| 67 | def_tags = ( |
||
| 68 | t_d_tags % definition.case_tags.replace("-", "‍-‍") |
||
| 69 | if definition.case_tags |
||
| 70 | else "" |
||
| 71 | ) |
||
| 72 | |||
| 73 | def_body = DefinitionFormatter(definition).tagged_definition_body(key, t_d_body) |
||
| 74 | word_name = DefinitionFormatter(definition).tagged_word_name(t_word_name) |
||
| 75 | word_origin_x = DefinitionFormatter(definition).tagged_word_origin_x( |
||
| 76 | t_word_origin |
||
| 77 | ) |
||
| 78 | |||
| 79 | definition = t_def % f"{def_tags}{def_gram}{def_body}" |
||
| 80 | return t_def_line % f"{word_name}{word_origin_x}{definition}" |
||
| 81 |