Bases: PyventusException
A custom Pyventus exception for handling missing imports within the package.
Notes:
-
This class provides a robust mechanism for handling and identifying potential
import exceptions within the Pyventus package.
-
This class inherits from the base PyventusException
class, allowing it to be
raised as needed.
Source code in pyventus/core/exceptions/pyventus_import_exception.py
| class PyventusImportException(PyventusException):
"""
A custom Pyventus exception for handling missing imports within the package.
**Notes:**
- This class provides a robust mechanism for handling and identifying potential
import exceptions within the Pyventus package.
- This class inherits from the base `PyventusException` class, allowing it to be
raised as needed.
"""
def __init__(self, import_name: str, *, is_optional: bool = False, is_dependency: bool = False) -> None:
"""
Initialize an instance of `PyventusImportException`.
:param import_name: The name of the missing import.
:param is_optional: A flag indicating whether the missing import is optional
or required for the package to work. Defaults to `False` (required).
:param is_dependency: A flag indicating whether the missing import is an
external dependency or not. Defaults to `False` (local import).
"""
# Store the import name and properties.
self.import_name: str = import_name
self.is_optional: bool = is_optional
self.is_dependency: bool = is_dependency
# Initialize the base PyventusException class with the error message.
super().__init__(
f"Missing {'optional ' if is_optional else ''}{'dependency' if is_dependency else 'import'}: {import_name}",
)
|
Attributes
errors
instance-attribute
errors: str | list[str] = errors if errors else __name__
import_name
instance-attribute
import_name: str = import_name
is_optional
instance-attribute
is_optional: bool = is_optional
is_dependency
instance-attribute
is_dependency: bool = is_dependency
Functions
__init__
__init__(import_name: str, *, is_optional: bool = False, is_dependency: bool = False) -> None
Initialize an instance of PyventusImportException
.
PARAMETER |
DESCRIPTION |
import_name
|
The name of the missing import.
TYPE:
str
|
is_optional
|
A flag indicating whether the missing import is optional or required for the package to work. Defaults to False (required).
TYPE:
bool
DEFAULT:
False
|
is_dependency
|
A flag indicating whether the missing import is an external dependency or not. Defaults to False (local import).
TYPE:
bool
DEFAULT:
False
|
Source code in pyventus/core/exceptions/pyventus_import_exception.py
| def __init__(self, import_name: str, *, is_optional: bool = False, is_dependency: bool = False) -> None:
"""
Initialize an instance of `PyventusImportException`.
:param import_name: The name of the missing import.
:param is_optional: A flag indicating whether the missing import is optional
or required for the package to work. Defaults to `False` (required).
:param is_dependency: A flag indicating whether the missing import is an
external dependency or not. Defaults to `False` (local import).
"""
# Store the import name and properties.
self.import_name: str = import_name
self.is_optional: bool = is_optional
self.is_dependency: bool = is_dependency
# Initialize the base PyventusException class with the error message.
super().__init__(
f"Missing {'optional ' if is_optional else ''}{'dependency' if is_dependency else 'import'}: {import_name}",
)
|