# Buggy code
def _get_valid_object(
    cls, module_path: Path, object_name: Optional[str]
) -> Generator[Any, None, None]:
    """
    Generator returning objects with matching object_type and object_name in the path given.
    :param module_path: absolute path to the module
    :param object_name: Class name of the object
    :return: generator containing matching objects
    """

    # Generate spec based on absolute path
    # Pass object_name as first argument to have logging print a reasonable name.
    spec = importlib.util.spec_from_file_location(object_name or "", str(module_path))
    module = importlib.util.module_from_spec(spec)
    try:
        spec.loader.exec_module(module)  # type: ignore # importlib does not use typehints
    except (ModuleNotFoundError, SyntaxError) as err:
        # Catch errors in case a specific module is not installed
        logger.warning(f"Could not import {module_path} due to '{err}'")

    valid_objects_gen = (
        obj
        for name, obj in inspect.getmembers(module, inspect.isclass)
        if (object_name is None or object_name == name)
        and cls.object_type in obj.__bases__
    )
    return valid_objects_gen


# Traceback (Exception)
2020-02-20 22:47:28,025 - freqtrade - ERROR - Fatal exception!
Traceback (most recent call last):
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 20, in wrapper
for arg in chain(args, kwargs.values())
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 36, in main
return_code = args['func'](args)
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 76, in start_hyperopt
hyperopt.start()
File "/freqtrade/freqtrade/optimize/hyperopt.py", line 488, in start
preprocessed = self.backtesting.strategy.tickerdata_to_dataframe(data)
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in tickerdata_to_dataframe
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 448, in <dictcomp>
for pair, pair_data in tickerdata.items()}
File "/freqtrade/freqtrade/strategy/interface.py", line 464, in advise_indicators
return self.populate_indicators(dataframe, metadata)
File "/freqtrade/user_data/strategies/MyDev.py", line 205, in populate_indicators
dataframe['mfi'] = ta.MFI(dataframe)
File "talib/_abstract.pxi", line 352, in talib._ta_lib.Function.__call__
File "talib/_abstract.pxi", line 383, in talib._ta_lib.Function.__call_function
File "/opt/tradebot/freqtrade/.env/lib/python3.7/site-packages/talib/__init__.py", line 24, in wrapper
return func(*args, **kwargs)
File "talib/_func.pxi", line 8454, in talib._ta_lib.MFI
Exception: volume is not double

# Fixed code
def _get_valid_object(
    cls, module_path: Path, object_name: Optional[str], enum_failed: bool = False
) -> Iterator[Any]:
    """
    Generator returning objects with matching object_type and object_name in the path given.
    :param module_path: absolute path to the module
    :param object_name: Class name of the object
    :param enum_failed: If True, will return None for modules which fail.
        Otherwise, failing modules are skipped.
    :return: generator containing matching objects
    """

    # Generate spec based on absolute path
    # Pass object_name as first argument to have logging print a reasonable name.
    spec = importlib.util.spec_from_file_location(object_name or "", str(module_path))
    module = importlib.util.module_from_spec(spec)
    try:
        spec.loader.exec_module(module)  # type: ignore # importlib does not use typehints
    except (ModuleNotFoundError, SyntaxError) as err:
        # Catch errors in case a specific module is not installed
        logger.warning(f"Could not import {module_path} due to '{err}'")
        if enum_failed:
            return iter([None])

    valid_objects_gen = (
        obj
        for name, obj in inspect.getmembers(module, inspect.isclass)
        if (
            (object_name is None or object_name == name)
            and issubclass(obj, cls.object_type)
            and obj is not cls.object_type
        )
    )
    return valid_objects_gen