Failed Conditions
Pull Request — master (#1152)
by Lasse
03:36
created

coalib.output._iimport_objects()   F

Complexity

Conditions 18

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 18
dl 0
loc 33
rs 2.7088

How to fix   Complexity   

Complexity

Complex classes like coalib.output._iimport_objects() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
def fail_acquire_settings(log_printer, settings_names_dict):
2
    """
3
    This method throws an exception if any setting needs to be acquired.
4
5
    :param log_printer:     Printer responsible for logging the messages.
6
    :param settings:        A dictionary with the settings name as key and
7
                            a list containing a description in [0] and the
8
                            name of the bears who need this setting in [1]
9
                            and following.
10
    :raises AssertionError: If any setting is required.
11
    :raises TypeError:      If `settings_names_dict` is not a dictionary.
12
    """
13
    if not isinstance(settings_names_dict, dict):
14
        raise TypeError("The settings_names_dict parameter has to be a "
15
                        "dictionary.")
16
17
    required_settings = settings_names_dict.keys()
18
    if len(required_settings) != 0:
19
        msg = ("During execution, we found that some required"
20
               "settings were not provided. They are:\n")
21
22
        for name, setting in settings_names_dict.items():
23
            msg += "{} (from {}) - {}".format(name, setting[1], setting[0])
24
25
        log_printer.err(msg)
26
        raise AssertionError
27