• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

deepset-ai / haystack / 13855199401

14 Mar 2025 11:01AM UTC coverage: 90.0% (+0.08%) from 89.922%
13855199401

Pull #9037

github

web-flow
Merge 621afb687 into 3d7d65a26
Pull Request #9037: Chat Generatol Protocol POC

9702 of 10780 relevant lines covered (90.0%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.57
haystack/lazy_imports.py
1
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
2
#
3
# SPDX-License-Identifier: Apache-2.0
4

5
from types import TracebackType
1✔
6
from typing import Optional, Type
1✔
7

8
from lazy_imports.try_import import _DeferredImportExceptionContextManager
1✔
9

10
DEFAULT_IMPORT_ERROR_MSG = "Try 'pip install {}'"
1✔
11

12

13
class LazyImport(_DeferredImportExceptionContextManager):
1✔
14
    """
15
    A context manager that provides controlled handling of import errors.
16

17
    It adds the possibility to customize the error messages.
18

19
    NOTE: Despite its name, this class does not delay the actual import operation.
20
    For installed modules: executes the import immediately.
21
    For uninstalled modules: captures the error and defers it until check() is called.
22
    """
23

24
    def __init__(self, message: str = DEFAULT_IMPORT_ERROR_MSG) -> None:
1✔
25
        super().__init__()
1✔
26
        self.import_error_msg = message
1✔
27

28
    def __exit__(
1✔
29
        self, exc_type: Optional[Type[Exception]], exc_value: Optional[Exception], traceback: Optional[TracebackType]
30
    ) -> Optional[bool]:
31
        """
32
        Exit the context manager.
33

34
        Args:
35
            exc_type:
36
                Raised exception type. :obj:`None` if nothing is raised.
37
            exc_value:
38
                Raised exception object. :obj:`None` if nothing is raised.
39
            traceback:
40
                Associated traceback. :obj:`None` if nothing is raised.
41

42
        Returns:
43
            :obj:`None` if nothing is deferred, otherwise :obj:`True`.
44
            :obj:`True` will suppress any exceptions avoiding them from propagating.
45

46
        """
47
        if isinstance(exc_value, ImportError):
1✔
48
            message = (
×
49
                f"Failed to import '{exc_value.name}'. {self.import_error_msg.format(exc_value.name)}. "
50
                f"Original error: {exc_value}"
51
            )
52
            self._deferred = (exc_value, message)
×
53
            return True
×
54
        return None
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc