o
    Û¾ik  ã                   @   s4   d dl Z d dlmZ d dlmZ G dd„ deƒZdS )é    N)ÚChainMap)Útypesc                   @   sB   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚDataModelManagerzBManages mapping of FE types to their corresponding data model
    Nc                 C   s   |pi | _ t ¡ | _dS )z 
        Parameters
        -----------
        handlers: Mapping[Type, DataModel] or None
            Optionally provide the initial handlers mapping.
        N)Ú	_handlersÚweakrefÚWeakKeyDictionaryÚ_cache)ÚselfÚhandlers© r   úP/home/ubuntu/.local/lib/python3.10/site-packages/numba/core/datamodel/manager.pyÚ__init__   s   
zDataModelManager.__init__c                 C   s   t |tjƒsJ ‚|| j|< dS )zNRegister the datamodel factory corresponding to a frontend-type class
        N)Ú
issubclassr   ÚTyper   )r	   Ú	fetypeclsÚhandlerr   r   r   Úregister   s   zDataModelManager.registerc                 C   sF   z| j | W S  ty   Y nw | jt|ƒ }|| |ƒ }| j |< |S )zMReturns the corresponding datamodel given the frontend-type instance
        )r   ÚKeyErrorr   Útype)r	   Úfetyper   Úmodelr   r   r   Úlookup   s   ÿzDataModelManager.lookupc                 C   s
   |   |¡S )zShorthand for lookup()
        )r   )r	   r   r   r   r   Ú__getitem__(   s   
zDataModelManager.__getitem__c                 C   s   t | j ¡ ƒS )z’
        Make a copy of the manager.
        Use this to inherit from the default data model and specialize it
        for custom target.
        )r   r   Úcopy)r	   r   r   r   r   -   s   zDataModelManager.copyc                 C   s   t | j|jƒ}t|ƒS )aÕ  Create a new DataModelManager by chaining the handlers mapping of
        `other_manager` with a fresh handlers mapping.

        Any existing and new handlers inserted to `other_manager` will be
        visible to the new manager. Any handlers inserted to the new manager
        can override existing handlers in `other_manager` without actually
        mutating `other_manager`.

        Parameters
        ----------
        other_manager: DataModelManager
        )r   r   r   )r	   Úother_managerÚchainedr   r   r   Úchain5   s   zDataModelManager.chain)N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r      s    
r   )r   Úcollectionsr   Ú
numba.corer   Úobjectr   r   r   r   r   Ú<module>   s    