U
    ?hk                     @   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   N/var/www/html/venv/lib/python3.8/site-packages/numba/core/datamodel/manager.py__init__   s    
zDataModelManager.__init__c                 C   s   t |tjst|| j|< dS )zNRegister the datamodel factory corresponding to a frontend-type class
        N)
issubclassr   TypeAssertionErrorr   )r	   Z	fetypeclshandlerr   r   r   register   s    zDataModelManager.registerc                 C   sH   z| j | W S  tk
r    Y nX | 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	   Zother_managerZ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   Z
numba.corer   objectr   r   r   r   r   <module>   s   