B
     \H                 @   s4  d Z ddlmZmZmZ ddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZ ddl
mZ ddlmZ ddlmZ g ZG dd	 d	eZG d
d deZG dd deZeejG dd deZG dd deZday\ddlZe eddZ!e"dd e!#dD dk r*dZ$e	%e$ e&ej'(ddr>e&W n. e&k
rn   G dd deZ)dd Z*Y nX ddlm+Z+m,Z,m-Z-m.Z.m/Z/ G dd  d eZ0G d!d" d"eZ1i Z2dddddd#e2d$< e.j3e.j4e.j5e.j6e.j7d#e2d%< e.j3e.j8e.j9e.j8e.j7d#e2d&< e.j5e.j4e.j9e.j:e.j7d#e2d'< e.j8e.j8e.j6e.j:e.j7d#e2d(< e2d$ Z;G d)d* d*eZ<d+d Z*d,Z=d-Z>d.Z?d/e= Z@d0ZAd1e= ZBeC ZDe>eDd2< eAeDd3< eBeDd4< e?eDd5< e@eDd6< d7d8 ZEG d9d: d:eZFG d;d< d<eGZHG d=d> d>eHZIG d?d@ d@eHZJG dAdB dBeJZKG dCdD dDeJZLG dEdF dFeJZMG dGdH dHeHZNG dIdJ dJeHZOG dKdL dLeHZPG dMdN dNeHZQG dOdP dPePZRG dQdR dReHZSG dSdT dTeSZTG dUdV dVeHZUG dWdX dXeHZVG dYdZ dZeHZWG d[d\ d\eHZXG d]d^ d^eSZYG d_d` d`eSZZdadb Z[ej\]e^Z_i Z`ejadcdd Zbeded ec d D 7 ZdS )fz%
Numba-specific errors and warnings.
    )print_functiondivisionabsolute_importN)defaultdict)six)wraps)abstractmethodc               @   s   e Zd ZdZdS )NumbaWarningz8
    Base category for all Numba compiler warnings.
    N)__name__
__module____qualname____doc__ r   r   +lib/python3.7/site-packages/numba/errors.pyr	      s   r	   c               @   s   e Zd ZdZdS )PerformanceWarningzV
    Warning category for when an operation might not be
    as fast as expected.
    N)r
   r   r   r   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdS )ParallelSafetyWarningzc
    Warning category for when an operation in a prange
    might not have parallel semantics.
    N)r
   r   r   r   r   r   r   r   r   $   s   r   c               @   sH   e Zd Zedd Zedd Zedd Zedd Zed	d
 ZdS )_ColorSchemec             C   s   d S )Nr   )selfmsgr   r   r   code0   s    z_ColorScheme.codec             C   s   d S )Nr   )r   r   r   r   r   errmsg4   s    z_ColorScheme.errmsgc             C   s   d S )Nr   )r   r   r   r   r   filename8   s    z_ColorScheme.filenamec             C   s   d S )Nr   )r   r   r   r   r   indicate<   s    z_ColorScheme.indicatec             C   s   d S )Nr   )r   r   r   r   r   	highlight@   s    z_ColorScheme.highlightN)	r
   r   r   r   r   r   r   r   r   r   r   r   r   r   -   s
   r   c               @   s>   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd ZdS )_DummyColorSchemeNc             C   s   d S )Nr   )r   themer   r   r   __init__G   s    z_DummyColorScheme.__init__c             C   s   d S )Nr   )r   r   r   r   r   r   J   s    z_DummyColorScheme.codec             C   s   d S )Nr   )r   r   r   r   r   r   M   s    z_DummyColorScheme.errmsgc             C   s   d S )Nr   )r   r   r   r   r   r   P   s    z_DummyColorScheme.filenamec             C   s   d S )Nr   )r   r   r   r   r   r   S   s    z_DummyColorScheme.indicatec             C   s   d S )Nr   )r   r   r   r   r   r   V   s    z_DummyColorScheme.highlight)N)	r
   r   r   r   r   r   r   r   r   r   r   r   r   r   E   s   
r   __version__z0.0.0c             C   s   g | ]}t |qS r   )int).0xr   r   r   
<listcomp>e   s    r!   .)r      	   zNInsufficiently recent colorama version found. Numba requires colorama >= 0.3.9Z(NUMBA_DISABLE_ERROR_MESSAGE_HIGHLIGHTINGc               @   s>   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd ZdS )NOPColorSchemeNc             C   s"   |d k	rt dtj| |d d S )Nz specifying a theme has no effect)r   )
ValueErrorr   r   )r   r   r   r   r   r   v   s    zNOPColorScheme.__init__c             C   s   |S )Nr   )r   r   r   r   r   r   {   s    zNOPColorScheme.codec             C   s   |S )Nr   )r   r   r   r   r   r   ~   s    zNOPColorScheme.errmsgc             C   s   |S )Nr   )r   r   r   r   r   r      s    zNOPColorScheme.filenamec             C   s   |S )Nr   )r   r   r   r   r   r      s    zNOPColorScheme.indicatec             C   s   |S )Nr   )r   r   r   r   r   r      s    zNOPColorScheme.highlight)N)	r
   r   r   r   r   r   r   r   r   r   r   r   r   r%   u   s   
r%   c               C   s   t d krt a t S )N)_termcolor_instr%   r   r   r   r   	termcolor   s    r(   )initreinitdeinitForeStylec               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	
ColorShellFc             C   s   t   d| _d S )NT)r)   _has_initialized)r   r   r   r   r      s    zColorShell.__init__c             C   s   | j rt  d S )N)r/   r*   )r   r   r   r   	__enter__   s    zColorShell.__enter__c             G   s   t j t  d S )N)r-   	RESET_ALLr+   )r   
exc_detailr   r   r   __exit__   s    zColorShell.__exit__N)r
   r   r   r/   r   r0   r3   r   r   r   r   r.      s   r.   c               @   s$   e Zd Zdd Zdd Zdd ZdS )reset_terminalc             C   s   t d| _d S )N    )	bytearray_buf)r   r   r   r   r      s    zreset_terminal.__init__c             C   s   | j S )N)r7   )r   r   r   r   r0      s    zreset_terminal.__enter__c             G   s   |  j ttjd7  _ d S )Nzutf-8)r7   r6   r-   r1   encode)r   r2   r   r   r   r3      s    zreset_terminal.__exit__N)r
   r   r   r   r0   r3   r   r   r   r   r4      s   r4   )r   r   r   r   r   Zno_colorZdark_bgZlight_bgZblue_bgZ
jupyter_nbc               @   sP   e Zd ZefddZdejfddZdd Zdd	 Z	d
d Z
dd Zdd ZdS )HighlightColorSchemec             C   sD   |d | _ |d | _|d | _|d | _|d | _tj| |d d S )Nr   r   r   r   r   )r   )_code_errmsg	_filename	_indicate
_highlightr   r   )r   r   r   r   r   r      s    




zHighlightColorScheme.__init__Nc          
   C   sf   d}|r||7 }|r||7 }t  : t "}||d7 }||d7 }W d Q R X |dS Q R X d S )N zutf-8)r.   r4   r8   decode)r   r   ZcolorZstyleZfeaturesZmur   r   r   _markup   s    zHighlightColorScheme._markupc             C   s   |  || jS )N)rA   r:   )r   r   r   r   r   r      s    zHighlightColorScheme.codec             C   s   |  || jS )N)rA   r;   )r   r   r   r   r   r      s    zHighlightColorScheme.errmsgc             C   s   |  || jS )N)rA   r<   )r   r   r   r   r   r      s    zHighlightColorScheme.filenamec             C   s   |  || jS )N)rA   r=   )r   r   r   r   r   r      s    zHighlightColorScheme.indicatec             C   s   |  || jS )N)rA   r>   )r   r   r   r   r   r      s    zHighlightColorScheme.highlight)r
   r   r   default_themer   r-   ZBRIGHTrA   r   r   r   r   r   r   r   r   r   r9      s   r9   c              C   s    t d krttjj } t| a t S )N)r'   themesnumbaconfigZCOLOR_SCHEMEr9   )Zschemer   r   r   r(      s    a-  
Please report the error message and traceback, along with a minimal reproducer
at: https://github.com/numba/numba/issues/new

If more help is needed please feel free to speak to the Numba core developers
directly at: https://gitter.im/numba/numba

Thanks in advance for your help in improving Numba!
z
Unsupported functionality was found in the code Numba was trying to compile.

If this functionality is important to you please file a feature request at:
https://github.com/numba/numba/issues/new
a  
Unsupported Python functionality was found in the code Numba was trying to
compile. This error could be due to invalid code, does the code work
without Numba? (To temporarily disable Numba JIT, set the `NUMBA_DISABLE_JIT`
environment variable to non-zero, and then rerun the code).

If the code is valid and the unsupported functionality is important to you
please file a feature request at: https://github.com/numba/numba/issues/new

To see Python/NumPy features supported by the latest release of Numba visit:
http://numba.pydata.org/numba-doc/dev/reference/pysupported.html
and
http://numba.pydata.org/numba-doc/dev/reference/numpysupported.html
a  
Numba could not make a constant out of something that it decided should be
a constant. This could well be a current limitation in Numba's internals,
however please first check that your code is valid for compilation,
particularly with respect to string interpolation (not supported!) and
the requirement of compile time constants as arguments to exceptions:
http://numba.pydata.org/numba-doc/latest/reference/pysupported.html?highlight=exceptions#constructs

If the code is valid and the unsupported functionality is important to you
please file a feature request at: https://github.com/numba/numba/issues/new

If you think your code should work with Numba. %s
a  
This is not usually a problem with Numba itself but instead often caused by
the use of unsupported features or an issue in resolving types.

To see Python/NumPy features supported by the latest release of Numba visit:
http://numba.pydata.org/numba-doc/dev/reference/pysupported.html
and
http://numba.pydata.org/numba-doc/dev/reference/numpysupported.html

For more information about typing errors and how to debug them visit:
http://numba.pydata.org/numba-doc/latest/user/troubleshoot.html#my-code-doesn-t-compile

If you think your code should work with Numba, please report the error message
and traceback, along with a minimal reproducer at:
https://github.com/numba/numba/issues/new
z
-------------------------------------------------------------------------------
This should not have happened, a problem has occurred in Numba's internals.
%s
Zunsupported_errortypingZ
reportableZinterpreterZconstant_inferencec                s2   t | tr| nd  fdd} s*|| S |S dS )zDefine a deprecation decorator.
    An optional string should refer to the new API to be used instead.

    Example:
      @deprecated
      def old_func(): ...

      @deprecated('new_func')
      def old_func(): ...Nc                s    fdd}t  |S )Nc                 s4   d}r|d7 }t j| jtdd  | |S )Nz!Call to deprecated function "{}".z
 Use "{}" instead.   )category
stacklevel)warningswarnformatr
   DeprecationWarning)argskwargsr   )funcsubstr   r   wrapper[  s    
z.deprecated.<locals>.decorator.<locals>.wrapper)r   )rP   rR   )rQ   )rP   r   	decoratorZ  s    zdeprecated.<locals>.decorator)
isinstancestr)argrS   r   )rQ   r   
deprecatedM  s
    rW   c               @   s0   e Zd ZdZdd Zejd	ddZdd ZdS )
WarningsFixerz
    An object "fixing" warnings of a given category caught during
    certain phases.  The warnings can have their filename and lineno fixed,
    and they are deduplicated as well.
    c             C   s   || _ tt| _d S )N)	_categoryr   set	_warnings)r   rH   r   r   r   r   r  s    zWarningsFixer.__init__Nc          	   c   s   t jdd}t d| j dV  W dQ R X xh|D ]`}t|j}t|j| jr||pV|j}|p`|j	}| j
|||jf | q2t ||j|j|j	 q2W dS )zN
        Store warnings and optionally fix their filename and lineno.
        T)recordalwaysN)rJ   catch_warningssimplefilterrY   rU   message
issubclassrH   r   linenor[   addwarn_explicit)r   r   rb   Zwlistwr   r   r   r   r^   w  s    




zWarningsFixer.catch_warningsc             C   sR   xBt | j D ]0\\}}}}x t |D ]}t|||| q(W qW | j  dS )z+
        Emit all stored warnings.
        N)sortedr[   itemsrJ   rd   clear)r   r   rb   rH   Zmessagesr   r   r   r   flush  s    zWarningsFixer.flush)NN)	r
   r   r   r   r   
contextlibcontextmanagerr^   ri   r   r   r   r   rX   k  s
   rX   c                   s:   e Zd Zd fdd	Zedd Zdd Zd	d
 Z  ZS )
NumbaErrorNTc                sf   || _ || _|rt j}ndd }|rHtt| |d|| f  ntt| |d|f  d S )Nc             S   s   | S )Nr   )r    r   r   r   r     s    z&NumbaError.__init__.<locals>.highlightz%s
%s
z%s)r   locr(   r   superrl   r   Z	strformat)r   r   rm   Zhighlightingr   )	__class__r   r   r     s    

zNumbaError.__init__c             C   s*   y| j S  tk
r$   g  | _ }|S X d S )N)Z	_contextsAttributeError)r   Zlstr   r   r   contexts  s
    
zNumbaError.contextsc             C   sD   | j | t dt d }|| t| j |}|f| _| S )zv
        Add contextual info.  The exception message is expanded with the new
        contextual information.
        z{0}
z[{1}] During: {2})rq   appendr(   r   r   rL   lenrN   )r   r   fZnewmsgr   r   r   add_context  s    zNumbaError.add_contextc             C   s   |f| j dd  | _ dS )zD
        Change the error message to the given new message.
           N)rN   )r   Znew_messager   r   r   patch_message  s    zNumbaError.patch_message)NT)	r
   r   r   r   propertyrq   ru   rw   __classcell__r   r   )ro   r   rl     s   rl   c               @   s   e Zd ZdZdS )UnsupportedErrorzG
    Numba does not have an implementation for this functionality.
    N)r
   r   r   r   r   r   r   r   rz     s   rz   c               @   s   e Zd ZdZdS )IRErrorz7
    An error occurred during Numba IR generation.
    N)r
   r   r   r   r   r   r   r   r{     s   r{   c               @   s   e Zd ZdZdS )RedefinedErrorzU
    An error occurred during interpretation of IR due to variable redefinition.
    N)r
   r   r   r   r   r   r   r   r|     s   r|   c                   s"   e Zd ZdZd fdd	Z  ZS )NotDefinedErrorzK
    An undefined variable is encountered during interpretation of IR.
    Nc                s&   || _ d| }tt| j||d d S )NzVariable '%s' is not defined.)rm   )namern   r}   r   )r   r~   rm   r   )ro   r   r   r     s    zNotDefinedError.__init__)N)r
   r   r   r   r   ry   r   r   )ro   r   r}     s   r}   c               @   s   e Zd ZdZdS )VerificationErrora6  
    An error occurred during IR verification. Once Numba's internal
    representation (IR) is constructed it is then verified to ensure that
    terminators are both present and in the correct places within the IR. If
    it is the case that this condition is not met, a VerificationError is
    raised.
    N)r
   r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdZdS )
MacroErrorz3
    An error occurred during macro expansion.
    N)r
   r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdZdS )DeprecationErrorz&
    Functionality is deprecated.
    N)r
   r   r   r   r   r   r   r   r     s   r   c                   s"   e Zd ZdZd fdd	Z  ZS )LoweringErrorz,
    An error occurred during lowering.
    Nc                s   t t| j||d d S )N)rm   )rn   r   r   )r   r   rm   )ro   r   r   r     s    zLoweringError.__init__)N)r
   r   r   r   r   ry   r   r   )ro   r   r     s   r   c               @   s   e Zd ZdZdS )UnsupportedParforsErrorzL
    An error ocurred because parfors is not supported on the platform.
    N)r
   r   r   r   r   r   r   r   r     s   r   c               @   s   e Zd ZdZdS )ForbiddenConstructzN
    A forbidden Python construct was encountered (e.g. use of locals()).
    N)r
   r   r   r   r   r   r   r   r   
  s   r   c               @   s   e Zd ZdZdS )TypingErrorz#
    A type inference failure.
    N)r
   r   r   r   r   r   r   r   r     s   r   c                   s   e Zd Zd fdd	Z  ZS )UntypedAttributeErrorNc                sP   t |dd }|d k	r&|tkr&d| }nd}|j||d}tt| j||d d S )NZpymodzPUse of unsupported NumPy function 'numpy.%s' or unsupported use of the function.z)Unknown attribute '{attr}' of type {type})typeattr)rm   )getattrnprL   rn   r   r   )r   valuer   rm   moduler   )ro   r   r   r     s    zUntypedAttributeError.__init__)N)r
   r   r   r   ry   r   r   )ro   r   r     s   r   c                   s"   e Zd ZdZd fdd	Z  ZS )ByteCodeSupportErrorzA
    Failure to extract the bytecode of the user's function.
    Nc                s   t t| j||d d S )N)rm   )rn   r   r   )r   r   rm   )ro   r   r   r   *  s    zByteCodeSupportError.__init__)N)r
   r   r   r   r   ry   r   r   )ro   r   r   %  s   r   c               @   s   e Zd ZdZdS )CompilerErrorz0
    Some high-level error in the compiler.
    N)r
   r   r   r   r   r   r   r   r   .  s   r   c                   s"   e Zd ZdZd fdd	Z  ZS )ConstantInferenceErrorz,
    Failure during constant inference.
    Nc                s   t t| j||d d S )N)rm   )rn   r   r   )r   r   rm   )ro   r   r   r   :  s    zConstantInferenceError.__init__)N)r
   r   r   r   r   ry   r   r   )ro   r   r   5  s   r   c                   s    e Zd ZdZ fddZ  ZS )InternalErrorzA
    For wrapping internal error occured within the compiler
    c                s   t t| t| || _d S )N)rn   r   r   rU   Zold_exception)r   Z	exception)ro   r   r   r   C  s    zInternalError.__init__)r
   r   r   r   r   ry   r   r   )ro   r   r   >  s   r   c               @   s   e Zd ZdZdS )RequireLiteralValuezj
    For signalling that a function's typing requires a constant value for
    some of its arguments.
    N)r
   r   r   r   r   r   r   r   r   H  s   r   c               @   s   e Zd ZdZdS )LiteralTypingErrorz*
    Failure in typing a Literal type
    N)r
   r   r   r   r   r   r   r   r   P  s   r   c             C   s   | j ||S )N)rL   )ZfmtrN   rO   r   r   r   _format_msgW  s    r   c       	   
   o   s   | dt}|dd}|dk	r6|jts6t| y
dV  W n tk
rv } z|	t
| ||  W dd}~X Y nl tk
r } zN||	t
| ||}ddlm} |jrt d nd}tt||| W dd}~X Y nX dS )a!  
    A contextmanager that prepend contextual information to any exception
    raised within.  If the exception type is not an instance of NumbaError,
    it will be wrapped into a InternalError.   The exception class can be
    changed by providing a "errcls_" keyword argument with the exception
    constructor.

    The first argument is a message that describes the context.  It can be a
    format string.  If there are additional arguments, it will be used as
    ``fmt_.format(*args, **kwargs)`` to produce the final message string.
    Zerrcls_rm   Nr   )rE   rG   )popr   getr   
startswith_numba_pathloc_infoupdaterl   ru   r   	ExceptionrD   rE   ZFULL_TRACEBACKSsysexc_infor   Zreraiser   )	Zfmt_rN   rO   Zerrclsrm   eZnewerrrE   tbr   r   r   new_error_context_  s    

r   c             C   s6   g | ].\}}| d st|trt|ttfr|qS )_)r   rT   r   ra   r   Warning)r   r~   r   r   r   r   r!   ~  s    )er   Z
__future__r   r   r   abcrj   osr   rJ   rD   Znumpyr   collectionsr   r   	functoolsr   r   __all__r   r	   r   RuntimeWarningr   Zadd_metaclassABCMetaobjectr   r   r'   Zcoloramar   Zcolorama_versiontuplesplitr   rK   ImportErrorenvironr   r%   r(   r)   r*   r+   r,   r-   r.   r4   rC   ZBLUEZYELLOWZWHITEZGREENZREDZBLACKZMAGENTAZCYANrB   r9   Zfeedback_detailsZunsupported_error_infoZinterpreter_error_infoZconstant_inference_infoZtyping_error_infoZreportable_issue_infodictZerror_extrasrW   rX   r   rl   rz   r{   r|   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   pathdirname__file__r   r   rk   r   globalsrg   r   r   r   r   <module>   s   	
$++			
