
    ,YHhI                        d dl mZ d dlZd dlZd dlmZ d dlmZ dZ G d d      ZddZ	 G d	 d
ej                        Zy)    )annotationsN)TracebackType)Anyza
Could not find `optuna-integration` for `{0}`.
Please run `pip install optuna-integration[{0}]`.c                  H    e Zd ZdZddZd	dZ	 	 	 	 	 	 	 	 d
dZddZddZy)&_DeferredImportExceptionContextManagerzContext manager to defer exceptions from imports.

    Catches :exc:`ImportError` and :exc:`SyntaxError`.
    If any exception is caught, this class raises an :exc:`ImportError` when being checked.

    c                    d | _         y N	_deferredselfs    H/var/www/html/planif/env/lib/python3.12/site-packages/optuna/_imports.py__init__z/_DeferredImportExceptionContextManager.__init__   s	    7;    c                    | S )zJEnter the context manager.

        Returns:
            Itself.

         r   s    r   	__enter__z0_DeferredImportExceptionContextManager.__enter__   s	     r   c                    t        |t        t        f      rft        |t              rdj                  |j                  |      }n/t        |t              rdj                  |j
                  |      }nJ ||f| _        yy)a   Exit the context manager.

        Args:
            exc_type:
                Raised exception type. :obj:`None` if nothing is raised.
            exc_value:
                Raised exception object. :obj:`None` if nothing is raised.
            traceback:
                Associated traceback. :obj:`None` if nothing is raised.

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

        zTried to import '{}' but failed. Please make sure that the package is installed correctly to use this feature. Actual error: {}.zTried to import a package but failed due to a syntax error in {}. Please make sure that the Python version is correct to use this feature. Actual error: {}.TN)
isinstanceImportErrorSyntaxErrorformatnamefilenamer   )r   exc_type	exc_value	tracebackmessages        r   __exit__z/_DeferredImportExceptionContextManager.__exit__#   s{    * i+{!;<)[1Q&3  I{3! &++Y7	  u'1DNr   c                    | j                   du S )zReturn whether the context manager has caught any exceptions.

        Returns:
            :obj:`True` if no exceptions are caught, :obj:`False` otherwise.

        Nr
   r   s    r   is_successfulz4_DeferredImportExceptionContextManager.is_successfulK   s     ~~%%r   c                R    | j                   | j                   \  }}t        |      |y)zCheck whether the context manager has caught any exceptions.

        Raises:
            :exc:`ImportError`:
                If any exception was caught from the caught exception.

        N)r   r   )r   r   r   s      r   checkz,_DeferredImportExceptionContextManager.checkT   s.     >>%!%Iwg&I5 &r   N)returnNone)r$   z('_DeferredImportExceptionContextManager')r   ztype[Exception] | Noner   zException | Noner   zTracebackType | Noner$   zbool | None)r$   bool)	__name__
__module____qualname____doc__r   r   r   r!   r#   r   r   r   r   r      sG    <&(& $& (	&
 
&P&
6r   r   c                     t               S )zCreate a context manager that can wrap imports of optional packages to defer exceptions.

    Returns:
        Deferred import context manager.

    )r   r   r   r   
try_importr,   a   s     233r   c                  4     e Zd ZdZd fdZddZddZ xZS )_LazyImporta  Module wrapper for lazy import.

    This class wraps the specified modules and lazily imports them only when accessed.
    Otherwise, `import optuna` is slowed down by importing all submodules and
    dependencies even if not required.
    Within this project's usage, importlib override this module's attribute on the first
    access and the imported submodule is directly accessed from the second access.

    Args:
        name: Name of module to apply lazy import.
    c                2    t         |   |       || _        y r	   )superr   _name)r   r   	__class__s     r   r   z_LazyImport.__init__x   s    
r   c                    t        j                  | j                        }| j                  j	                  |j                         |S r	   )	importlibimport_moduler1   __dict__update)r   modules     r   _loadz_LazyImport._load|   s1    ((4V__-r   c                6    t        | j                         |      S r	   )getattrr9   )r   items     r   __getattr__z_LazyImport.__getattr__   s    tzz|T**r   )r   strr$   r%   )r$   ztypes.ModuleType)r<   r>   r$   r   )r'   r(   r)   r*   r   r9   r=   __classcell__)r2   s   @r   r.   r.   k   s    

+r   r.   )r$   r   )
__future__r   r4   typesr   typingr   "_INTEGRATION_IMPORT_ERROR_TEMPLATEr   r,   
ModuleTyper.   r   r   r   <module>rE      sB    "    8 #O6 O6d4+%"" +r   