3
tûœ]ÅÊ  ã               @   s,  d Z ddlZddlZddlmZ ddlZddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZ ddlmZ dd	lmZmZ ejd
ƒZdd„ Zdd„ Zdd„ Zdddddddddddddddd hZd!d"hZd#d$d%hZd&d'd(hZd)d*„ Zd+d,„ Zed-d.d/gƒZG d0d1„ d1ej ƒZ!G d2d3„ d3ej"ƒZ#d4d5„ Z$dS )6z<Check Python 2 code for Python 2/3 source-compatible issues.é    N)Ú
namedtuple)Úbases)ÚcheckersÚ
interfaces)Úutils)Úfind_try_except_wrapper_nodeÚnode_ignores_exception)ÚWarningScope)Ú	INFERENCEÚINFERENCE_FAILUREz^0+$c             C   sF   t j| ƒrdS tjd| ƒrByt| dƒ W n tk
r<   dS X dS d S )NFz0\d+é   T)Ú_ZEROÚmatchÚreÚintÚ
ValueError)Úliteral© r   ú9/tmp/pip-build-fn42xldr/pylint/pylint/checkers/python3.pyÚ_is_old_octal+   s    
r   c             C   s&   t | tjƒrdS t | tjƒo$d| jkS )NTÚdict)Ú
isinstanceÚastroidÚDictÚInstanceÚ	basenames)Úvaluer   r   r   Ú_inferred_value_is_dict7   s    r   c             C   s   t | dd ƒdkS )NÚnameÚ__builtin__Úbuiltins)r   r    )Úgetattr)Únoder   r   r   Ú_is_builtin=   s    r#   ÚiterÚlistÚtupleÚsortedÚsetÚsumÚanyÚallÚ	enumerater   ÚfilterÚreversedÚmaxÚminÚ	frozensetÚOrderedDictÚjoinÚfrom_iterablezbuiltins.list.extendzbuiltins.dict.updatezbuiltins.set.updateÚitemsÚkeysÚvaluesc             C   sV  | j }t|tjƒrdS t|tjƒr4|j| kr0dS �nt|tjƒrºt|jtjƒr`|jj	t
kr~dS nt|jtjƒr~|jjtkr~dS tj|jƒ}|r¸|jƒ tkrždS |jƒ }|r¸|j	dkr¸dS n†t|tjƒrøt|jd tjtjfƒrøt|jd jƒdkrödS nHt|tjƒ�r.t|jƒdk�r.|jd d dk�r.dS t|tjƒ�r@dS t|tjƒ�rRdS dS )z{Check if the node is being used as an iterator.

    Definition is taken from lib2to3.fixer_util.in_special_context().
    TÚ	itertoolsr   é   ÚinF)Úparentr   r   ÚForZComprehensionr$   ÚCallÚfuncÚNamer   Ú_ACCEPTS_ITERATORÚ	AttributeÚattrnameÚATTRIBUTES_ACCEPTS_ITERATORr   Ú
safe_inferÚqnameÚ _BUILTIN_METHOD_ACCEPTS_ITERATORÚrootÚAssignÚtargetsÚListÚTupleÚlenÚeltsÚCompareÚopsÚ	YieldFromÚStarred)r"   r;   ÚinferredrG   r   r   r   Ú_in_iterating_context\   sB    
rS   c             C   s    | j }t|tjtjtjtjfƒS )zAChecks if an import node is in the context of a conditional.
    )r;   r   r   Z	TryExceptÚExceptHandlerÚIfÚIfExp)r"   r;   r   r   r   Ú_is_conditional_import”   s    rW   ÚBranchr"   Úis_py2_onlyc            a       sØ  e Zd ZejZdZdZ�d&�d'd	d
dd�d(gifdddd�d)gifdddej	�d*gdœfdddd�d+if�d,�d-�d.�d/�d0�d1�d2�d3�d4�d5�d6�d7�d8�d9�d:�d;�d<�d=�d>�d?�d@�dA�dBdedfdgd�dCgifdjdkdld�dDgif�dE�dF�dG�dH�dI�dJ�dK�dL�dMdŠd‹dŒd�dNgif�dO�dP�dQ�dR�dS�dT�dU�dV�dW�dX�dY�dZ�d[�d\�d]�d^�d_�d`�da�db�dc�dd�de�df�dg�dhdÝœCZ
edÞdßdàdádâdãdädådædçdèdédêdëdìdídîdïgƒZedðdñdòdódôdõdöd÷dødùdúgƒZedûdüdýdþdÿ�d �d�d�d�d�d�d�d�d�d	�d
�d�dgƒZ�de�dgƒi�de�d�d�d�d�dgƒi�de�d�d�d�d�d�d�d�d�d�d�d �d!�d"�d#�d$�d%�d&�d'�d(�d)�d*�d+�d,�d-�d.gƒie�d/�d0�d1�d2�d3�d4�d5�d6�d7�d8�d9�d:�d;�d<�d=�d>�d?�d@�dA�dB�dC�dD�dE�dF�dG�dH�dI�dJ�dK�dL�dM�dN�dO�dP�dQ�dR�dS�dT�dU�dV�dW�dX�dY�dZ�d[�d\�d]�d^�d_�d`�da�db�dc�dd�de�df�dg�dh�di�dj�dk�dl�dm�dn�do�dp�dq�dr�ds�dt�du�dv�dw�dx�dy�dz�d{�d|�d}�d~�d�d€�d��d‚�dƒ�d„�d…�d†�d‡�dˆ�d‰�dŠ�d‹g]ƒ�dŒe�d��dŽ�d��d��d‘�d’�d“�d”�d•�d–�d—�d˜�d™�dš�d›�dœ�d��dž�dŸ�d �d¡�d¢�d£�d¤�d¥�d¦�d§�d¨�d©�dª�d™�d«�d¬�d­�d®�d¯g$ƒi�d°e�d±hƒi�d²e�d³�d´�dµ�d¶�d·�d¸�d¹�dº�d»�d¼�d½�d¾�d¿�dÀ�dÁ�dÂ�dÃ�dÄ�dÅ�dÆ�dÇ�dÈ�dÉ�dÊ�dË�dÌ�dÍ�dÎ�dÏ�dÐ�dÑ�dÒ�dÓ�dÔ�dÕ�dÖ�d×�dØ�dÙh'ƒi�de�dÚhƒi�dÛœZe�dÜ�dÝ„ �diD ƒƒZ‡ f�dã�dä„Z�dj‡ f�då�dæ„	Z�dç�dè„ Z�dé�dê„ Z�dë�dì„ Z�dí�dî„ Z�dï�dð„ Z�dñ�dò„ Z�dó�dô„ Zejdƒ�dõ�dö„ ƒZejdÛƒ�d÷�dø„ ƒZ�dù�dú„ Zejdƒ�dû�dü„ ƒZ�dk�dþ�dÿ„Z �d �d„ Z!�d�d„ Z"ejdcƒ�d�d„ ƒZ#ejdWƒ�d�d„ ƒZ$�d�d	„ Z%e&�d
�d„ ƒZ'e&�d�d„ ƒZ(e&�d�d„ ƒZ)e&�d�d„ ƒZ*�d�d„ Z+�d�d„ Z,ejdfƒ�d�d„ ƒZ-�d�d„ Z.�d�d„ Z/ejd¨dÒƒ�d�d„ ƒZ0ejd
dÛƒ�d�d„ ƒZ1ejdƒ�d �d!„ ƒZ2ejdkdƒ�d"�d#„ ƒZ3�d$�d%„ Z4‡  Z5S (l  ÚPython3CheckerFÚpython3úprint statement usedúprint-statementúGUsed when a print statement is used (`print` is a function in Python 3)úParameter unpacking specifiedúparameter-unpackingúTUsed when parameter unpacking is specified for a function(Python 3 doesn't allow it)z=Implicit unpacking of exceptions is not supported in Python 3zunpacking-in-exceptzwPython3 will not allow implicit unpacking of exceptions in except clauses. See http://www.python.org/dev/peps/pep-3110/Ú	old_namesÚW0712úold-unpacking-in-exceptz=Use raise ErrorClass(args) instead of raise ErrorClass, args.zold-raise-syntaxzZUsed when the alternate raise syntax 'raise foo, bar' is used instead of 'raise foo(bar)'.ÚW0121úold-old-raise-syntaxzUse of the `` operatorÚbacktickzYUsed when the deprecated "``" (backtick) operator is used instead  of the str() function.ÚW0333úold-backtick)Úscoperb   z%Import * only allowed at module levelzimport-star-module-levelzNUsed when the import star syntax is used somewhere else than the module level.Ú
maxversioné   r   úapply built-in referencedúapply-builtinúKUsed when the apply built-in function is referenced (missing from Python 3)úbasestring built-in referencedúbasestring-builtinúPUsed when the basestring built-in function is referenced (missing from Python 3)úbuffer built-in referencedúbuffer-builtinúLUsed when the buffer built-in function is referenced (missing from Python 3)úcmp built-in referencedúcmp-builtinúIUsed when the cmp built-in function is referenced (missing from Python 3)úcoerce built-in referencedúcoerce-builtinúLUsed when the coerce built-in function is referenced (missing from Python 3)úexecfile built-in referencedúexecfile-builtinúNUsed when the execfile built-in function is referenced (missing from Python 3)úfile built-in referencedúfile-builtinúJUsed when the file built-in function is referenced (missing from Python 3)úlong built-in referencedúlong-builtinúJUsed when the long built-in function is referenced (missing from Python 3)úraw_input built-in referencedúraw_input-builtinúOUsed when the raw_input built-in function is referenced (missing from Python 3)úreduce built-in referencedúreduce-builtinúLUsed when the reduce built-in function is referenced (missing from Python 3)ú!StandardError built-in referencedústandarderror-builtinúSUsed when the StandardError built-in function is referenced (missing from Python 3)úunicode built-in referencedúunicode-builtinúMUsed when the unicode built-in function is referenced (missing from Python 3)úxrange built-in referencedúxrange-builtinúLUsed when the xrange built-in function is referenced (missing from Python 3)ú__coerce__ method definedúcoerce-methodúIUsed when a __coerce__ method is defined (method is not used by Python 3)ú__delslice__ method definedúdelslice-methodúKUsed when a __delslice__ method is defined (method is not used by Python 3)ú__getslice__ method definedúgetslice-methodúKUsed when a __getslice__ method is defined (method is not used by Python 3)ú__setslice__ method definedúsetslice-methodúKUsed when a __setslice__ method is defined (method is not used by Python 3)ú7import missing `from __future__ import absolute_import`úno-absolute-importútUsed when an import is not accompanied by ``from __future__ import absolute_import`` (default behaviour in Python 3)ú!division w/o __future__ statementúold-divisionú’Used for non-floor division w/o a float literal or ``from __future__ import division`` (Python 3 returns a float for int division unconditionally)úCalling a dict.iter*() methodúdict-iter-methodú]Used for calls to dict.iterkeys(), itervalues() or iteritems() (Python 3 lacks these methods)úCalling a dict.view*() methodúdict-view-methodú]Used for calls to dict.viewkeys(), viewvalues() or viewitems() (Python 3 lacks these methods)ú#Called a next() method on an objectúnext-method-calledúZUsed when an object's next() method is called (Python 3 uses the next() built-in function)ú.Assigning to a class's __metaclass__ attributeúmetaclass-assignmentú�Used when a metaclass is specified by assigning to __metaclass__ (Python 3 specifies the metaclass as a class statement argument)z-Indexing exceptions will not work on Python 3zindexing-exceptionzSIndexing exceptions will not work on Python 3. Use `exception.args[index]` instead.ÚW0713úold-indexing-exceptionzRaising a string exceptionzraising-stringzGUsed when a string exception is raised. This will not work on Python 3.ÚW0701úold-raising-stringúreload built-in referencedúreload-builtinú�Used when the reload built-in function is referenced (missing from Python 3). You can use instead imp.reload or importlib.reload.ú__oct__ method definedú
oct-methodúGUsed when an __oct__ method is defined (method is not used by Python 3)ú__hex__ method definedú
hex-methodúFUsed when a __hex__ method is defined (method is not used by Python 3)ú__nonzero__ method definedúnonzero-methodúJUsed when a __nonzero__ method is defined (method is not used by Python 3)ú__cmp__ method definedú
cmp-methodúFUsed when a __cmp__ method is defined (method is not used by Python 3)úinput built-in referencedúinput-builtinúYUsed when the input built-in is referenced (backwards-incompatible semantics in Python 3)úround built-in referencedúround-builtinúYUsed when the round built-in is referenced (backwards-incompatible semantics in Python 3)úintern built-in referencedúintern-builtinúMUsed when the intern built-in is referenced (Moved to sys.intern in Python 3)úunichr built-in referencedúunichr-builtinúAUsed when the unichr built-in is referenced (Use chr in Python 3)z*map built-in referenced when not iteratingzmap-builtin-not-iteratingzeUsed when the map built-in is referenced in a non-iterating context (returns an iterator in Python 3)ÚW1631úimplicit-map-evaluationú*zip built-in referenced when not iteratingúzip-builtin-not-iteratingúeUsed when the zip built-in is referenced in a non-iterating context (returns an iterator in Python 3)ú,range built-in referenced when not iteratingúrange-builtin-not-iteratingúcUsed when the range built-in is referenced in a non-iterating context (returns a range in Python 3)ú-filter built-in referenced when not iteratingúfilter-builtin-not-iteratingúhUsed when the filter built-in is referenced in a non-iterating context (returns an iterator in Python 3)ú-Using the cmp argument for list.sort / sortedúusing-cmp-argumentú±Using the cmp argument for list.sort or the sorted builtin should be avoided, since it was removed in Python 3. Using either `key` or `functools.cmp_to_key` should be preferred.ú6Implementing __eq__ without also implementing __hash__úeq-without-hashúãUsed when a class implements __eq__ but not __hash__.  In Python 2, objects get object.__hash__ as the default implementation, in Python 3 objects get None as their default __hash__ implementation if they also implement __eq__.ú__div__ method definedú
div-methodú‘Used when a __div__ method is defined.  Using `__truediv__` and setting__div__ = __truediv__ should be preferred.(method is not used by Python 3)ú__idiv__ method definedúidiv-methodú–Used when an __idiv__ method is defined.  Using `__itruediv__` and setting__idiv__ = __itruediv__ should be preferred.(method is not used by Python 3)ú__rdiv__ method definedúrdiv-methodú•Used when a __rdiv__ method is defined.  Using `__rtruediv__` and setting__rdiv__ = __rtruediv__ should be preferred.(method is not used by Python 3)ú%Exception.message removed in Python 3úexception-message-attributeúYUsed when the message attribute is accessed on an Exception.  Use str(exception) instead.ú$non-text encoding used in str.decodeúinvalid-str-codecúqUsed when using str.encode or str.decode with a non-text encoding.  Use codecs module to handle arbitrary codecs.úsys.maxint removed in Python 3úsys-max-intú9Used when accessing sys.maxint.  Use sys.maxsize instead.úModule moved in Python 3úbad-python3-importú?Used when importing a module that no longer exists in Python 3.ú4Accessing a deprecated function on the string moduleúdeprecated-string-functionúKUsed when accessing a string function that has been deprecated in Python 3.ú:Using str.translate with deprecated deletechars parametersúdeprecated-str-translate-callúwUsed when using the deprecated deletechars parameters from str.translate.  Use re.sub to remove the desired characters ú7Accessing a deprecated function on the itertools moduleúdeprecated-itertools-functionúNUsed when accessing a function on itertools that has been removed in Python 3.ú1Accessing a deprecated fields on the types moduleúdeprecated-types-fieldúGUsed when accessing a field on types that has been removed in Python 3.únext method definedúnext-method-definedúyUsed when a next method is defined that would be an iterator in Python 2 but is treated as a normal function in Python 3.ú(dict.items referenced when not iteratingúdict-items-not-iteratingú_Used when dict.items is referenced in a non-iterating context (returns an iterator in Python 3)ú'dict.keys referenced when not iteratingúdict-keys-not-iteratingú^Used when dict.keys is referenced in a non-iterating context (returns an iterator in Python 3)ú)dict.values referenced when not iteratingúdict-values-not-iteratingú`Used when dict.values is referenced in a non-iterating context (returns an iterator in Python 3)ú4Accessing a removed attribute on the operator moduleúdeprecated-operator-functionúQUsed when accessing a field on operator module that has been removed in Python 3.ú2Accessing a removed attribute on the urllib moduleúdeprecated-urllib-functionúXUsed when accessing a field on urllib module that has been removed or moved in Python 3.ú(Accessing a removed xreadlines attributeúxreadlines-attributeúTUsed when accessing the xreadlines() function on a file stream, removed in Python 3.ú/Accessing a removed attribute on the sys moduleúdeprecated-sys-functionúLUsed when accessing a field on sys module that has been removed in Python 3.ú=Using an exception object that was bound by an except handlerúexception-escapeúºEmitted when using an exception, that was bound in an except handler, outside of the except handler. On Python 3 these exceptions will be deleted once they get out of the except handler.ú6Using a variable that was bound inside a comprehensionúcomprehension-escapeú¸Emitted when using a variable, that was bound in a comprehension handler, outside of the comprehension itself. On Python 3 these variables will be deleted outside of the comprehension.)CZE1601ZE1602ZE1603ZE1604ZE1605ZE1609ZW1601ZW1602ZW1603ZW1604ZW1605ZW1606ZW1607ZW1608ZW1609ZW1610ZW1611ZW1612ZW1613ZW1614ZW1615ZW1616ZW1617ZW1618ZW1619ZW1620ZW1621ZW1622ZW1623ZW1624ZW1625ZW1626ZW1627ZW1628ZW1629ZW1630ZW1632ZW1633ZW1634ZW1635ZW1636ZW1637ZW1638ZW1639ZW1640ZW1641ZW1642ZW1643ZW1644ZW1645ZW1646ZW1647ZW1648ZW1649ZW1650ZW1651ZW1652ZW1653ZW1654ZW1655ZW1656ZW1657ZW1658ZW1659ZW1660ZW1661ZW1662ÚapplyÚ
basestringÚbufferÚcmpZcoerceZexecfileÚfileÚinputÚinternÚlongÚ	raw_inputÚreduceÚroundÚStandardErrorÚunichrÚunicodeÚxrangeÚreloadZ
__coerce__Z__delslice__Z__getslice__Z__setslice__Z__oct__Z__hex__Ú__nonzero__Z__cmp__Z__div__Z__idiv__Z__rdiv__Úbase64_codecÚbase64Úbase_64Ú	bz2_codecÚbz2Ú	hex_codecÚhexÚquopri_codecÚquopriÚquotedprintableÚquoted_printableÚuu_codecÚuuÚ
zlib_codecÚzlibÚzipÚrot13Úrot_13ÚsysZmaxintr8   ÚizipÚifilterÚimapÚizip_longestÚifilterfalseÚtypesZEllipsisTypeZ
XRangeTypeZComplexTypeZ
StringTypeZTypeTypeZLongTypeZUnicodeTypeZ	ClassTypeZ
BufferTypeZStringTypesZNotImplementedTypeZNoneTypeZInstanceTypeZ	FloatTypeZ	SliceTypeZUnboundMethodTypeZ
ObjectTypeZIntTypeZ	TupleTypeZListTypeZDictTypeÚFileTypeZDictionaryTypeZBooleanTypeZDictProxyTypeÚanydbmÚBaseHTTPServerr   ÚCGIHTTPServerÚConfigParserÚcopy_regÚcPickleÚ	cStringIOÚCookieÚ	cookielibÚdbhashÚdumbdbmZdumbdbÚDialogÚDocXMLRPCServerÚ
FileDialogZFixTkÚgdbmÚhtmlentitydefsÚ
HTMLParserÚhttplibÚ
markupbaseÚQueueÚreprÚrobotparserÚScrolledTextÚSimpleDialogÚSimpleHTTPServerÚSimpleXMLRPCServerÚStringIOÚdummy_threadÚSocketServerztest.test_supportÚTkinterÚTixÚTkconstantsÚtkColorChooserÚtkCommonDialogÚTkdndÚtkFileDialogÚtkFontÚtkMessageBoxÚtkSimpleDialogÚUserListÚ
UserStringÚwhichdbÚ_winregÚ	xmlrpclibZaudiodevZBastionZbsddb185Zbsddb3ZCanvasZcfmfileZclÚcommandsÚcompilerZdircacheÚdlÚ	exceptionZfpformatZhtmllibZihooksZimageopZimputilZlinuxaudiodevÚmd5ZmhlibZ	mimetoolsZ
MimeWriterZmimifyZ	multifileÚmutexÚnewZpopen2Z	posixfileZpureZrexecZrfc822ZsetsZshaZsgmllibZsreZ	stringoldZsunaudioÚsvztest.testallÚthreadZtimingZtoaiffÚuserÚurllib2ÚurlparseÚstringÚ	maketransÚatofÚatoiZatolÚ
capitalizeÚ
expandtabsÚfindÚrfindÚindexÚrindexÚcountÚlowerÚlettersÚsplitÚrsplitZsplitfieldsr3   Z
joinfieldsÚlstripÚrstripÚstripÚswapcaseÚ	translateÚupperÚljustÚrjustÚcenterÚzfillÚreplaceZ	lowercaseZ	uppercaseZ
atol_errorZ
atof_errorZ
atoi_errorZindex_errorÚoperatorÚdivÚurllibÚaddbaseÚaddclosehookÚaddinfoÚ
addinfourlZalways_safeZbasejoinÚftpcacheÚ	ftperrorsÚ
ftpwrapperÚ
getproxiesÚgetproxies_environmentZgetproxies_macosx_sysconfÚmainÚ	noheadersÚpathname2urlÚproxy_bypassÚproxy_bypass_environmentZproxy_bypass_macosx_sysconfÚquoteÚ
quote_plusÚ
reporthookÚ	splitattrÚ	splithostÚ
splitnportÚsplitpasswdÚ	splitportÚ
splitqueryÚsplittagÚ	splittypeÚ	splituserÚ
splitvalueÚunquoteÚunquote_plusÚunwrapÚurl2pathnameÚ
urlcleanupÚ	urlencodeÚurlopenÚurlretrieveZ	exc_clear)zsys-max-intzdeprecated-itertools-functionzdeprecated-types-fieldzbad-python3-importzdeprecated-string-functionzdeprecated-operator-functionzdeprecated-urllib-functionzdeprecated-sys-functionc             C   s   g | ]}t j|ƒjƒ ‘qS r   )r   Zextract_nodeÚ	repr_tree)Ú.0Úxr   r   r   ú
<listcomp>n  s   zPython3Checker.<listcomp>úsys.version_info[0] == 2úsys.version_info[0] < 3úsys.version_info == (2, 7)úsys.version_info <= (2, 7)úsys.version_info < (3, 0)c                s0   d| _ d| _tƒ | _g | _tt| ƒj||Ž d S )NF)Ú_future_divisionÚ_future_absolute_importr(   Ú_modules_warned_aboutÚ_branch_stackÚsuperrZ   Ú__init__)ÚselfÚargsÚkwargs)Ú	__class__r   r   rÒ  y  s
    zPython3Checker.__init__c                s4   |s| j o| j d j r0tt| ƒj|f|ž|Ž d S )Nr9   éÿÿÿÿ)rÐ  rY   rÑ  rZ   Úadd_message)rÓ  Zmsg_idÚalways_warnrÔ  rÕ  )rÖ  r   r   rØ  �  s    zPython3Checker.add_messagec             C   sd   t |jtjƒr>t |jjtjƒr>|jjjdkr`|jjdkr`dS n"t |jtjƒr`|jj	ƒ | j
kr`dS dS )NÚsixÚPY2TF)r   Útestr   rA   Úexprr?   r   rB   rN   rÄ  Ú_python_2_tests)rÓ  r"   r   r   r   Ú_is_py2_test‡  s    zPython3Checker._is_py2_testc             C   s   | j jt|| j|ƒƒƒ d S )N)rÐ  ÚappendrX   rß  )rÓ  r"   r   r   r   Úvisit_if”  s    zPython3Checker.visit_ifc             C   s   | j jƒ j|kst‚d S )N)rÐ  Úpopr"   ÚAssertionError)rÓ  r"   r   r   r   Úleave_if—  s    zPython3Checker.leave_ifc             C   s   | j jt|| j|ƒƒƒ d S )N)rÐ  rà  rX   rß  )rÓ  r"   r   r   r   Úvisit_ifexpš  s    zPython3Checker.visit_ifexpc             C   s   | j jƒ j|kst‚d S )N)rÐ  râ  r"   rã  )rÓ  r"   r   r   r   Úleave_ifexp�  s    zPython3Checker.leave_ifexpc             C   s   d| _ d| _dS )z*Clear checker state after previous module.FN)rÍ  rÎ  )rÓ  r"   r   r   r   Úvisit_module   s    zPython3Checker.visit_modulec             C   s�   |j ƒ rŒ|j| jkrH|j}|jjdƒr4|jdd
… }| j|d |d� nD|jdkrŒd}tj|tjd gƒrnd}t	|j
j
ƒ|krŒ| jd	|d� d S )NÚ__é   z-method)r"   Únextr9   z.staticmethodr   znext-method-definedéþÿÿÿ)Z	is_methodr   Ú_unused_magic_methodsÚ
startswithrØ  r   Zdecorated_withr   ÚBUILTINSrL   rÔ  )rÓ  r"   Úmethod_nameZfailing_arg_countr   r   r   Úvisit_functiondef¥  s    
z Python3Checker.visit_functiondefc             C   s.   x(|j D ]}t|tjƒr| jd|d� qW d S )Nzparameter-unpacking)r"   )rÔ  r   r   rK   rØ  )rÓ  r"   Úargr   r   r   Úvisit_arguments¸  s    zPython3Checker.visit_argumentsc                sÂ   dd„ ˆj D ƒ‰ ˆjjƒ }|jtjtjd�}t‡ ‡fdd„|jtjtjd�D ƒƒ}|rZd S t	ƒ }t
|ƒ}xT|D ]L}|jˆ ksn|jˆjksn|j|ksn|jƒ ˆkr qn|j|jƒ | jd|d� qnW d S )Nc             S   s"   h | ]}t |jtjƒr|jj’qS r   )r   Útargetr   Ú
AssignNamer   )rÅ  Ú	generatorr   r   r   ú	<setcomp>À  s   z0Python3Checker.visit_listcomp.<locals>.<setcomp>)Ú
skip_klassc             3   s(   | ] }|j ˆ kr|jˆjkr|V  qd S )N)r   Úlineno)rÅ  Úassign_name)Únamesr"   r   r   ú	<genexpr>È  s   z0Python3Checker.visit_listcomp.<locals>.<genexpr>zcomprehension-escape)r"   )Ú
generatorsr;   rj   Únodes_of_classr   r?   ÚFunctionDefr*   rô  r(   r%   r   rø  ÚaddrØ  )rÓ  r"   rj   Úscope_namesZhas_redefined_assign_nameZemitted_for_namesÚ
scope_namer   )rú  r"   r   Úvisit_listcomp¾  s(    




zPython3Checker.visit_listcompc             C   sh   |j |jƒ\}}t|ƒsdS |j| jkr,dS t|ƒsDtt|ƒtjƒrHdS |jj	ƒ d }| j
||d� dS )z+Detect when a "bad" built-in is referenced.Nz-builtin)r"   )Úlookupr   r#   Ú_bad_builtinsr   r   r   r   rT   r�  rØ  )rÓ  r"   Ú
found_nodeÚ_Úmessager   r   r   Ú
visit_nameß  s    
zPython3Checker.visit_namec             C   s   | j d|dd� d S )Nzprint-statementT)r"   rÙ  )rØ  )rÓ  r"   r   r   r   Úvisit_printî  s    zPython3Checker.visit_printTc             C   sx   xr| j jƒ D ]d\}}||kr|| jkrt|tƒrP|rp| jj|ƒ | j||d� q|r|| j|ƒr| j||d� qW d S )N)r"   )Ú_bad_python3_module_mapr5   rÏ  r   r1   rÿ  rØ  Úintersection)rÓ  r"   ÚmoduleÚ
attributesÚreport_on_modulesr  Z
module_mapr   r   r   Ú_warn_if_deprecatedò  s    
z"Python3Checker._warn_if_deprecatedc             C   sÒ   |j dkr>x†|jD ]&\}}|dkr*d| _q|dkrd| _qW nT| jsd| jjdƒrd| jd|d� d| _t|ƒ r’|j r’| j	||j dd„ |jD ƒƒ |jd	 d	 d
krÎ| jjdƒrÎt
|jƒ tjƒsÎ| jd|d� d S )NÚ
__future__ÚdivisionTÚabsolute_importzno-absolute-import)r"   c             S   s   h | ]}|d  ’qS )r   r   )rÅ  rÆ  r   r   r   rö  	  s    z2Python3Checker.visit_importfrom.<locals>.<setcomp>r   Ú*zimport-star-module-level)Úmodnamerú  rÍ  rÎ  ÚlinterÚis_message_enabledrØ  rW   Úlevelr  r   rj   r   ÚModule)rÓ  r"   r   r  r   r   r   Úvisit_importfromü  s     
zPython3Checker.visit_importfromc             C   sT   | j s&| jjdƒr&| jd|d� d| _ t|ƒsPx |jD ]\}}| j||d ƒ q6W d S )Nzno-absolute-import)r"   T)rÎ  r  r  rØ  rW   rú  r  )rÓ  r"   r   r  r   r   r   Úvisit_import  s    zPython3Checker.visit_importc             C   sX   d|j kr| jd|d� t|j ƒjdd„ |jƒ D ƒƒ}d|krTd|krT| jd|d� d S )	NZ__metaclass__zmetaclass-assignment)r"   c             s   s   | ]}|j V  qd S )N)r   )rÅ  rÆ  r   r   r   rû    s    z0Python3Checker.visit_classdef.<locals>.<genexpr>Ú__eq__Ú__hash__zeq-without-hash)ÚlocalsrØ  r(   ÚunionZ	mymethods)rÓ  r"   Zlocals_and_methodsr   r   r   Úvisit_classdef  s
    
zPython3Checker.visit_classdefc             C   sz   | j  rv|jdkrvxb|j|jfD ]D}tj|ƒ}|r t|tjƒrJt|j	t
ƒp^t|tjƒo^|jdk r P q W | jd|d� d S )Nú/r   zold-division)r"   )rÍ  ÚopÚleftÚrightr   rD   r   r   ÚConstr   r   r   r   rØ  )rÓ  r"   rñ  rR   r   r   r   Úvisit_binop!  s    
zPython3Checker.visit_binopc             C   sÞ   g }t |jtjƒr`|jjdkr`tj|jjƒ}|s4d S djt	j
ƒ}t |tjƒsX|jƒ |kr¬|j}nLt |jtjƒr¬|jjdkr¬tj|jƒ}|sŽd S djt	j
ƒ}|jƒ |kr¬|j}x,|p´g D ] }|jdkr¶| jd|d� d S q¶W d S )NÚsortz{}.listr'   z	{}.sortedr$  zusing-cmp-argument)r"   )r   r>   r   rA   rB   r   rD   rÝ  Úformatr   rî  rJ   rE   Úkeywordsr?   r   rñ  rØ  )rÓ  r"   rÕ  rR   Zbuiltins_listZbuiltins_sortedÚkwargr   r   r   Ú_check_cmp_argument5  s&    
z"Python3Checker._check_cmp_argumentc             C   s$   t | tjƒrt | jtƒS t | tjƒS )N)r   r   r$  r   Ústrr?   )r"   r   r   r   Ú_is_constant_string_or_nameO  s    z*Python3Checker._is_constant_string_or_namec             C   s   t | tjƒo| jd kS )N)r   r   r$  r   )r"   r   r   r   Ú_is_noneU  s    zPython3Checker._is_nonec             C   s    t | jƒ|kot| jƒo| j S )N)rL   rÔ  r+   r(  )r"   Znumber_of_argsr   r   r   Ú_has_only_n_positional_argsY  s    z*Python3Checker._has_only_n_positional_argsc             C   sJ   | rt nt}x8| D ]0}|tjkr&t}qt|tjƒo<t|jtƒsd S qW |S )N)r
   r   r   ÚUninferabler   r$  r   r+  )Úinferred_typesÚ
confidenceZinferred_typer   r   r   Ú_could_be_string]  s    

zPython3Checker._could_be_stringc       
      C   sŒ  | j |ƒ t|jtjƒ�rØtƒ }yŽxˆ|jjjƒ D ]x}|tjkr@q0|j	|ƒ t|tj
ƒrp| j||j|jjhdd� t|ƒr0|jjtkr0t|ƒs0dj|jjƒ}| j||d� q0W W n tjk
rÄ   Y nX |j�rr| j|ƒ}|�rn|jjdk�rt|jƒdk�r|jd �r|jd }| j||ƒ |jjd	k�rn| j|d
ƒ�rn| j|jd ƒ�rn| j|jd ƒ�rn| jd||d� d S |j�r~d S |jjdk�rœ| jd|d� n:|jjdk�rº| jd|d� n|jjd k�rˆ| jd|d� n°t|jtjƒ�rˆ|jj|jjƒd }t|ƒ�rˆ|jjd!k�r:t|ƒ�s:dj|jjƒ}| j||d� |jjdk�rˆ|j�rˆ|j}x0|�p`g D ]"}	|	jdk�rb| j|	j |ƒ P �qbW d S )"NF)r  zdict-{}-not-iterating)r"   ÚencodeÚdecoder9   r   r—  ré  zdeprecated-str-translate-call)r"   r1  rê  znext-method-calledÚiterkeysÚ
itervaluesÚ	iteritemszdict-iter-methodÚviewkeysÚ
viewvaluesÚ	viewitemszdict-view-methodr-   ÚmapÚrangerA  z{}-builtin-not-iteratingÚopenÚencoding)r3  r4  )r5  r6  r7  )r8  r9  r:  )r-   r;  r<  rA  )!r*  r   r>   r   rA   r(   rÝ  Úinferr/  rÿ  r  r  r   rB   r   ÚDICT_METHODSrS   r'  rØ  ÚInferenceErrorrÔ  r2  rL   Ú_validate_encodingr.  r-  r,  r(  r?   r  r#   rñ  r   )
rÓ  r"   r0  Zinferred_receiverÚcheckerZis_str_confidenceZ	first_argr  rÕ  r)  r   r   r   Ú
visit_callj  sv    






zPython3Checker.visit_callc             C   s.   t |tjƒr*|j}|| jkr*| jd|d� d S )Nzinvalid-str-codec)r"   )r   r   r$  r   Ú_invalid_encodingsrØ  )rÓ  r>  r"   r   r   r   r   rB  ½  s    
z!Python3Checker._validate_encodingc             C   sZ   y>x8|j jƒ D ]*}t|tjƒs qtj|ƒr| jd|d� qW W n tjk
rT   dS X dS )z Look for indexing exceptions. zindexing-exception)r"   N)	r   r?  r   r   r   r   Úinherit_from_std_exrØ  rA  )rÓ  r"   rR   r   r   r   Úvisit_subscriptÃ  s    
zPython3Checker.visit_subscriptc             C   s   t |jƒ tjƒr| j|ƒ d S )N)r   Zassign_typer   Ú	AugAssignÚvisit_attribute)rÓ  r"   r   r   r   Úvisit_assignattrÏ  s    zPython3Checker.visit_assignattrc             C   s   | j |ƒ d S )N)rI  )rÓ  r"   r   r   r   Úvisit_delattrÓ  s    zPython3Checker.visit_delattrc             C   s²   |j dkr| jd|d� dS d}yvxp|jjƒ D ]b}t|tjƒrltj|ƒrl|j |krl||j	kr^q.| jd|d� t|tj
ƒr.| j||j|j hdd� q.W W n tjk
r¬   dS X dS )	zLook for removed attributesZ
xreadlineszxreadlines-attribute)r"   Nr  zexception-message-attributeF)r  )rB   rØ  rÝ  r?  r   r   r   r   rF  Zinstance_attrsr  r  r   rA  )rÓ  r"   Zexception_messagerR   r   r   r   rI  Ö  s"    


zPython3Checker.visit_attributec                sÊ   dd„ ‰ t ˆjtjtjfƒr.| jdˆd� dS ˆjs8dS ˆjjƒ }|jtj	tj
d�}t|ƒ}‡ ‡fdd„|D ƒ}‡fd	d
„|jtjtj
d�D ƒ}x4|D ],‰t‡‡fdd„|D ƒƒr´q–| jdˆd� q–W dS )z@Visit an except handler block and check for exception unpacking.c             S   sH   | j ƒ }| }x$|r0||kr0t|tjƒ r0|j}qW t|tjƒoF|j| kS )N)rj   r   r   rT   r;   Útype)r"   rj   Úcurrentr   r   r   Ú_is_used_in_except_blockô  s    
zDPython3Checker.visit_excepthandler.<locals>._is_used_in_except_blockzunpacking-in-except)r"   N)r÷  c                s4   g | ],}|j ˆj j kr|jˆjkrˆ |ƒ r|‘qS r   )r   rø  )rÅ  r  )rN  r"   r   r   rÇ    s   z6Python3Checker.visit_excepthandler.<locals>.<listcomp>c                s    h | ]}|j ˆ j j kr|j’qS r   )r   rø  )rÅ  rù  )r"   r   r   rö    s   z5Python3Checker.visit_excepthandler.<locals>.<setcomp>c             3   s*   | ]"}ˆj |  k oˆ j k n  V  qd S )N)rø  )rÅ  Úelem)Úleaked_namer"   r   r   rû    s   z5Python3Checker.visit_excepthandler.<locals>.<genexpr>zexception-escape)r   r   r   rK   rJ   rØ  r;   rj   rý  r?   rþ  r%   rô  r*   )rÓ  r"   rj   r   Zpotential_leaked_namesZreassignments_for_same_namer   )rN  rP  r"   r   Úvisit_excepthandlerð  s(    



z"Python3Checker.visit_excepthandlerc             C   s   | j d|d� d S )Nrg   )r"   )rØ  )rÓ  r"   r   r   r   Ú
visit_repr   s    zPython3Checker.visit_reprc             C   s^   |j dkrdS |j }| j||ƒr$dS yttj|ƒƒ}W n tjk
rL   dS X | j||ƒ dS )z[Visit a raise statement and check for raising
        strings or old-raise-syntax.
        N)ÚexcÚ_check_raise_valuerê  r   Zunpack_inferrA  )rÓ  r"   rÝ  r   r   r   r   Úvisit_raise$  s    
zPython3Checker.visit_raisec             C   s2   t |tjƒr.|j}t |tƒr.| jd|d� dS d S )Nzraising-string)r"   T)r   r   r$  r   r+  rØ  )rÓ  r"   rÝ  r   r   r   r   rT  6  s    
z!Python3Checker._check_raise_value)r\   r]   r^   )r_   r`   ra   )rc   rd   )re   rf   )rh   ri   )rl   r   )rm   rn   ro   )rp   rq   rr   )rs   rt   ru   )rv   rw   rx   )ry   rz   r{   )r|   r}   r~   )r   r€   r�   )r‚   rƒ   r„   )r…   r†   r‡   )rˆ   r‰   rŠ   )r‹   rŒ   r�   )rŽ   r�   r�   )r‘   r’   r“   )r”   r•   r–   )r—   r˜   r™   )rš   r›   rœ   )r�   rž   rŸ   )r    r¡   r¢   )r£   r¤   r¥   )r¦   r§   r¨   )r©   rª   r«   )r¬   r­   r®   )r¯   r°   r±   )r²   r³   )r´   rµ   )r¶   r·   r¸   )r¹   rº   r»   )r¼   r½   r¾   )r¿   rÀ   rÁ   )rÂ   rÃ   rÄ   )rÅ   rÆ   rÇ   )rÈ   rÉ   rÊ   )rË   rÌ   rÍ   )rÎ   rÏ   rÐ   )rÑ   rÒ   )rÓ   rÔ   rÕ   )rÖ   r×   rØ   )rÙ   rÚ   rÛ   )rÜ   rÝ   rÞ   )rß   rà   rá   )râ   rã   rä   )rå   ræ   rç   )rè   ré   rê   )rë   rì   rí   )rî   rï   rð   )rñ   rò   ró   )rô   rõ   rö   )r÷   rø   rù   )rú   rû   rü   )rý   rþ   rÿ   )r   r  r  )r  r  r  )r  r  r  )r	  r
  r  )r  r  r  )r  r  r  )r  r  r  )r  r  r  )r  r  r  )r  r  r  )r  r  r   )rÈ  rÉ  rÊ  rË  rÌ  )F)T)6Ú__name__Ú
__module__Ú__qualname__r   ZIAstroidCheckerÚ__implements__Úenabledr   r	   ZNODEÚmsgsr1   r  rì  rE  r
  rÞ  rÒ  rØ  rß  rá  rä  rå  ræ  rç  rð  r   Zcheck_messagesrò  r  r  r	  r  r  r  r  r%  r*  Ústaticmethodr,  r-  r.  r2  rD  rB  rG  rJ  rK  rI  rQ  rR  rU  rT  Ú__classcell__r   r   )rÖ  r   rZ       sî      
                                                                                                                    





    !
	S0rZ   c            	   @   sd   e Zd ZejZdZdZdddddifd	d
dddgdœfdddddifdddddifdœZdd„ Z	dS )ÚPython3TokenCheckerr[   FzUse of long suffixzlong-suffixz~Used when "l" or "L" is used to mark a long integer. This will not work in Python 3, since `int` and `long` types have merged.rk   rl   r   zUse of the <> operatorzold-ne-operatorz\Used when the deprecated "<>" operator is used instead of "!=". This is removed in Python 3.ÚW0331úold-old-ne-operator)rk   rb   zUse of old octal literalzold-octal-literalzrUsed when encountering the old octal syntax, removed in Python 3. To use the new syntax, prepend 0o on the number.z-Non-ascii bytes literals not supported in 3.xznon-ascii-bytes-literalzdUsed when non-ascii bytes literals are found in a program. They are no longer supported in Python 3.)ZE1606ZE1607ZE1608ZE1610c             C   sÌ   xÆt |ƒD ]º\}\}}}}}|tjkrb|jƒ jdƒrH| jd|d d� nt|ƒrb| jd|d d� || d dkrŒ| jd|| d	 d d� |tjkr
|jd
ƒr
t	dd„ |D ƒƒr
| jd|d d� q
W d S )NÚlzlong-suffixr   )Úlinezold-octal-literalr9   z<>zold-ne-operatorré  Úbc             s   s   | ]}t |ƒd kr|V  qdS )é   N)Úord)rÅ  rO  r   r   r   rû  p  s    z5Python3TokenChecker.process_tokens.<locals>.<genexpr>znon-ascii-bytes-literal)
r,   ÚtokenizeÚNUMBERr�  ÚendswithrØ  r   ÚSTRINGrí  r*   )rÓ  ÚtokensÚidxÚtok_typeÚtokenÚstartr  r   r   r   Úprocess_tokense  s    
z"Python3TokenChecker.process_tokensN)rl   r   )rl   r   )r_  r`  )rl   r   )rl   r   )
rV  rW  rX  r   ZITokenCheckerrY  r   rZ  r[  ro  r   r   r   r   r^  ?  s(   r^  c             C   s    | j t| ƒƒ | j t| ƒƒ d S )N)Zregister_checkerrZ   r^  )r  r   r   r   Úregistert  s    rp  )%Ú__doc__r   rf  Úcollectionsr   r   r   Zpylintr   r   Zpylint.checkersr   Zpylint.checkers.utilsr   r   Zpylint.constantsr	   Zpylint.interfacesr
   r   Úcompiler   r   r   r#   r@   rC   rF   r@  rS   rW   rX   ZBaseCheckerrZ   ZBaseTokenCheckerr^  rp  r   r   r   r   Ú<module>   sd   

8	         (5