
^Yc           @   s   d  d l  m Z d  d l m Z d  d l m Z m Z d  d l m	 Z	 m
 Z
 m Z d e	 f d     YZ d e	 f d     YZ d	 S(
   i(   t   PyCF_ONLY_AST(   t   version_info(   t   messagest   checker(   t   TestCaset   skipIft   skipt   Testc           B   s  e  Z d    Z d   Z e e dJ k  d  d    Z e e dK k  d  d    Z d   Z e	 d  d	    Z
 e e dL k  d  d
    Z d   Z d   Z d   Z e	 d  d    Z e	 d  d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e e dM k d  d    Z e e dN k d  d    Z d   Z d   Z d   Z d    Z  e	 d!  d"    Z! d#   Z" d$   Z# d%   Z$ d&   Z% d'   Z& d(   Z' d)   Z( d*   Z) d+   Z* d,   Z+ d-   Z, d.   Z- d/   Z. d0   Z/ d1   Z0 d2   Z1 d3   Z2 d4   Z3 e e dO k  d5  d6    Z4 e e dP k  d5  d7    Z5 e e dQ k  d5  d8    Z6 e e dR k  d5  d9    Z7 e e dS k  d5  d:    Z8 e e dT k  d5  d;    Z9 e e dU k  d5  d<    Z: d=   Z; d>   Z< d?   Z= d@   Z> dA   Z? dB   Z@ e e dV k  dE  dF    ZA dG   ZB e e dW k  dE  dH    ZC dI   ZD RS(X   c         C   s   |  j  d t j  d  S(   Nt   bar(   t   flakest   mt   UndefinedName(   t   self(    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_undefined
   s    c         C   s   |  j  d  d  S(   Ns   [a for a in range(10) if a](   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_definedInListComp   s    i   s9   in Python 2 list comprehensions execute in the same scopec         C   s   |  j  d t j  d  S(   Ns2   
        [a for a in range(10)]
        a
        (   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_undefinedInListComp   s    s>   in Python 2 exception names stay bound after the except: blockc         C   s   |  j  d t j  d S(   s6   Exception names can't be used after the except: block.sx   
        try:
            raise ValueError('ve')
        except ValueError as exc:
            pass
        exc
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_undefinedExceptionName   s    c         C   s   |  j  d  d S(   s   Locals declared in except: blocks can be used after the block.

        This shows the example in test_undefinedExceptionName is
        different.sy   
        try:
            raise ValueError('ve')
        except ValueError as exc:
            e = exc
        e
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt    test_namesDeclaredInExceptBlocks&   s    s5   error reporting disabled due to false positives belowc         C   s   |  j  d t j  d S(   s   Exception names obscure locals, can't be used after.

        Last line will raise UnboundLocalError on Python 3 after exiting
        the except: block. Note next two examples for false positives to
        watch out for.s   
        exc = 'Original value'
        try:
            raise ValueError('ve')
        except ValueError as exc:
            pass
        exc
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt1   test_undefinedExceptionNameObscuringLocalVariable3   s    c         C   s   |  j  d t j  d S(   s   Exception names are unbound after the `except:` block.

        Last line will raise UnboundLocalError on Python 3 but would print out
        've' on Python 2.s   
        try:
            raise ValueError('ve')
        except ValueError as exc:
            pass
        print(exc)
        exc = 'Original value'
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt2   test_undefinedExceptionNameObscuringLocalVariable2D   s    c         C   s   |  j  d  d S(   s   Exception names obscure locals, can't be used after. Unless.

        Last line will never raise UnboundLocalError because it's only
        entered if no exception was raised.s   
        exc = 'Original value'
        try:
            raise ValueError('ve')
        except ValueError as exc:
            print('exception logged')
            raise
        exc
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt?   test_undefinedExceptionNameObscuringLocalVariableFalsePositive1U   s    c         C   s   |  j  d  d S(   s7   The exception name can be deleted in the except: block.s\   
        try:
            pass
        except Exception as exc:
            del exc
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_delExceptionInExceptd   s    c         C   s   |  j  d  d S(   s   Exception names obscure locals, can't be used after. Unless.

        Last line will never raise UnboundLocalError because `error` is
        only falsy if the `except:` block has not been entered.s   
        exc = 'Original value'
        error = None
        try:
            raise ValueError('ve')
        except ValueError as exc:
            error = 'exception logged'
        if error:
            print(error)
        else:
            exc
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt?   test_undefinedExceptionNameObscuringLocalVariableFalsePositive2m   s    c         C   s   |  j  d t j  d S(   s  Exception names obscure globals, can't be used after.

        Last line will raise UnboundLocalError on both Python 2 and
        Python 3 because the existence of that exception name creates
        a local scope placeholder for it, obscuring any globals, etc.s   
        exc = 'Original value'
        def func():
            try:
                pass  # nothing is raised
            except ValueError as exc:
                pass  # block never entered, exc stays unbound
            exc
        N(   R	   R
   t   UndefinedLocal(   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt2   test_undefinedExceptionNameObscuringGlobalVariable   s    c         C   s   |  j  d t j  d S(   s  Exception names obscure globals, can't be used after.

        Last line will raise NameError on Python 3 because the name is
        locally unbound after the `except:` block, even if it's
        nonlocal. We should issue an error in this case because code
        only working correctly if an exception isn't raised, is invalid.
        Unless it's explicitly silenced, see false positives below.s   
        exc = 'Original value'
        def func():
            global exc
            try:
                raise ValueError('ve')
            except ValueError as exc:
                pass  # block never entered, exc stays unbound
            exc
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt3   test_undefinedExceptionNameObscuringGlobalVariable2   s    		c         C   s   |  j  d  d S(   s   Exception names obscure globals, can't be used after. Unless.

        Last line will never raise NameError because it's only entered
        if no exception was raised.s  
        exc = 'Original value'
        def func():
            global exc
            try:
                raise ValueError('ve')
            except ValueError as exc:
                print('exception logged')
                raise
            exc
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt@   test_undefinedExceptionNameObscuringGlobalVariableFalsePositive1   s    
c         C   s   |  j  d  d S(   s   Exception names obscure globals, can't be used after. Unless.

        Last line will never raise NameError because `error` is only
        falsy if the `except:` block has not been entered.sN  
        exc = 'Original value'
        def func():
            global exc
            error = None
            try:
                raise ValueError('ve')
            except ValueError as exc:
                error = 'exception logged'
            if error:
                print(error)
            else:
                exc
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt@   test_undefinedExceptionNameObscuringGlobalVariableFalsePositive2   s    c         C   s   |  j  d  d  S(   NsQ   
        class a:
            def b():
                fu
        fu = 1
        (   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_functionsNeedGlobalScope   s    c         C   s   |  j  d  d  S(   Ns	   range(10)(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_builtins   s    c         C   s   |  j  d  d S(   sm   
        C{WindowsError} is sometimes a builtin name, so no warning is emitted
        for using it.
        t   WindowsErrorN(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_builtinWindowsError   s    c         C   s   |  j  d  d S(   sh   
        Use of the C{__file__} magic global should not emit an undefined name
        warning.
        t   __file__N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_magicGlobalsFile   s    c         C   s   |  j  d  d S(   sl   
        Use of the C{__builtins__} magic global should not emit an undefined
        name warning.
        t   __builtins__N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_magicGlobalsBuiltins   s    c         C   s   |  j  d  d S(   sh   
        Use of the C{__name__} magic global should not emit an undefined name
        warning.
        t   __name__N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_magicGlobalsName   s    c         C   s*   |  j  d t j  |  j  d d d d S(   s   
        Use of the C{__path__} magic global should not emit an undefined name
        warning, if you refer to it from a file called __init__.py.
        t   __path__t   filenames   package/__init__.pyN(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_magicGlobalsPath   s    c         C   s   |  j  d t j t j  d S(   s)   Can't find undefined names with import *.s   from fu import *; barN(   R	   R
   t   ImportStarUsedt   ImportStarUsage(   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_globalImportStar   s    	s   obsolete syntaxc         C   s#   |  j  d t j t j t j  d S(   sd   
        A local import * still allows undefined names to be found
        in upper scopes.
        sC   
        def a():
            from fu import *
        bar
        N(   R	   R
   R)   R   t   UnusedImport(   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_localImportStar   s    c         C   s   |  j  d  d S(   s-   Unpacked function parameters create bindings.s9   
        def a((bar, baz)):
            bar; baz
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_unpackedParameter  s    c         C   s   |  j  d  |  j  d  d S(   sd   
        "global" can make an otherwise undefined name in another function
        defined.
        s@   
        def a(): global fu; fu = 1
        def b(): fu
        sC   
        def c(): bar
        def b(): global bar; bar = 1
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_definedByGlobal  s    c         C   s   |  j  d  d S(   s5   
        "global" can accept multiple names.
        sS   
        def a(): global fu, bar; fu = 1; bar = 2
        def b(): fu; bar
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt!   test_definedByGlobalMultipleNames!  s    c         C   s   |  j  d t j  d S(   sD   
        A global statement in the global scope is ignored.
        sB   
        global x
        def foo():
            print(x)
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_globalInGlobalScope*  s    c         C   s   |  j  d t j  d S(   s@   A global statement does not prevent other names being undefined.sQ   
        def f1():
            s

        def f2():
            global m
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_global_reset_name_only4  s    t   todoc         C   s   |  j  d t j  d S(   s4   An unused global statement does not define the name.sQ   
        def f1():
            m

        def f2():
            global m
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_unused_global@  s    c         C   s   |  j  d t j  d S(   s   Del deletes bindings.s   a = 1; del a; aN(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_delK  s    c         C   s   |  j  d  d S(   s%   Del a global binding from a function.sY   
        a = 1
        def f():
            global a
            del a
        a
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_delGlobalO  s    c         C   s   |  j  d t j  d S(   s   Del an undefined name.s   del aN(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_delUndefinedY  s    c         C   s   |  j  d  d S(   s8   
        Ignores conditional bindings deletion.
        sq   
        context = None
        test = True
        if False:
            del(test)
        assert(test)
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_delConditional]  s    c         C   s   |  j  d  d S(   sh   
        Ignored conditional bindings deletion even if they are nested in other
        blocks.
        s   
        context = None
        test = True
        if False:
            with context():
                del(test)
        assert(test)
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_delConditionalNestedi  s    c         C   s   |  j  d  d S(   sb   
        Ignore bindings deletion if called inside the body of a while
        statement.
        s~   
        def test():
            foo = 'bar'
            while False:
                del foo
            assert(foo)
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_delWhilew  s    c         C   s   |  j  d  d S(   s   
        Ignore bindings deletion if called inside the body of a while
        statement and name is used inside while's test part.
        s   
        def _worker():
            o = True
            while o is not True:
                del o
                o = False
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_delWhileTestUsage  s    c         C   s   |  j  d  d S(   sx   
        Ignore bindings deletions if node is part of while's test, even when
        del is in a nested block.
        s   
        context = None
        def _worker():
            o = True
            while o is not True:
                while True:
                    with context():
                        del o
                o = False
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_delWhileNested  s    	c         C   s   |  j  d  d S(   s.   Global names are available from nested scopes.sO   
        a = 1
        def b():
            def c():
                a
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_globalFromNestedScope  s    c         C   s   |  j  d t j  d S(   s~   
        Test that referencing a local name that shadows a global, before it is
        defined, generates a warning.
        s_   
        a = 1
        def fun():
            a
            a = 2
            return a
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt(   test_laterRedefinedGlobalFromNestedScope  s    c         C   s   |  j  d t j  d S(   s   
        Test that referencing a local name in a nested scope that shadows a
        global declared in an enclosing scope, before it is defined, generates
        a warning.
        s   
            a = 1
            def fun():
                global a
                def fun2():
                    a
                    a = 2
                    return a
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt)   test_laterRedefinedGlobalFromNestedScope2  s    c         C   s   |  j  d t j  d S(   s  
        If a name defined in an enclosing scope is shadowed by a local variable
        and the name is used locally before it is bound, an unbound local
        warning is emitted, even if there is a class scope between the enclosing
        scope and the local scope.
        s   
        def f():
            x = 1
            class g:
                def h(self):
                    a = x
                    x = None
                    print(x, a)
            print(x)
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt"   test_intermediateClassScopeIgnored  s    	c         C   sN   |  j  d t j  j d } |  j r+ d n d } |  j | j d | f  d S(   s  
        Test that referencing a local name in a nested scope that shadows a
        variable declared in two different outer scopes before it is defined
        in the innermost scope generates an UnboundLocal warning which
        refers to the nearest shadowed name.
        s  
            def a():
                x = 1
                def b():
                    x = 2 # line 5
                    def c():
                        x
                        x = 3
                        return x
                    return x
                return x
        i    i   i   t   xN(   R	   R
   R   R   t   withDoctestt   assertEqualt   message_args(   R   t   exct   expected_line_num(    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt$   test_doubleNestingReportsClosestName  s    c         C   s   |  j  d t j  d S(   s   
        Test that referencing a local name in a nested scope that shadows a
        global, before it is defined, generates a warning.
        s   
            def fun():
                a = 1
                def fun2():
                    a
                    a = 1
                    return a
                return a
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt)   test_laterRedefinedGlobalFromNestedScope3  s    c         C   s/   |  j  d t j t j t j t j t j  d  S(   Ns   
            def f(seq):
                a = 0
                seq[a] += 1
                seq[b] /= 2
                c[0] *= 2
                a -= 3
                d += 4
                e[any] = 5
            (   R	   R
   R   t   UnusedVariable(   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt!   test_undefinedAugmentedAssignment  s    
c         C   s   |  j  d  d S(   s*   Nested classes can access enclosing scope.s   
        def f(foo):
            class C:
                bar = foo
                def f(self):
                    return foo
            return C()

        f(123).f()
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_nestedClass  s    	c         C   s   |  j  d t j  d S(   s=   Free variables in nested classes must bind at class creation.s   
        def f():
            class C:
                bar = foo
            foo = 456
            return foo
        f()
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_badNestedClass   s    c         C   s   |  j  d  d S(   s+   Star and double-star arg names are defined.s?   
        def f(a, *b, **c):
            print(a, b, c)
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_definedAsStarArgs+  s    s   new in Python 3c         C   s+   |  j  d  |  j  d  |  j  d  d S(   s!   Star names in unpack are defined.s7   
        a, *b = range(10)
        print(a, b)
        s7   
        *a, b = range(10)
        print(a, b)
        s=   
        a, *b, c = range(10)
        print(a, b, c)
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_definedAsStarUnpack2  s    c         C   s+   |  j  d  |  j  d  |  j  d  d S(   sS   
        Star names in unpack are used if RHS is not a tuple/list literal.
        s8   
        def f():
            a, *b = range(10)
        s:   
        def f():
            (*a, b) = range(10)
        s=   
        def f():
            [a, *b, c] = range(10)
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_usedAsStarUnpackB  s    c         C   sU   |  j  d t j t j  |  j  d t j t j  |  j  d t j t j t j  d S(   sQ   
        Star names in unpack are unused if RHS is a tuple/list literal.
        sC   
        def f():
            a, *b = any, all, 4, 2, 'un'
        sL   
        def f():
            (*a, b) = [bool, int, float, complex]
        sD   
        def f():
            [a, *b, c] = 9, 8, 7, 6, 5, 4
        N(   R	   R
   RI   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_unusedAsStarUnpackT  s    c         C   s   |  j  d  |  j  d  d S(   s#   Keyword-only arg names are defined.s>   
        def f(*, a, b=None):
            print(a, b)
        s\   
        import default_b
        def f(*, a, b=default_b):
            print(a, b)
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_keywordOnlyArgsf  s    c         C   s   |  j  d t j  d S(   s   Typo in kwonly name.sC   
        def f(*, a, b=default_c):
            print(a, b)
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_keywordOnlyArgsUndefinedt  s    c         C   s   |  j  d  |  j  d  d S(   s   Undefined annotations.s   
        from abc import note1, note2, note3, note4, note5
        def func(a: note1, *args: note2,
                 b: note3=12, **kw: note4) -> note5: pass
        sk   
        def func():
            d = e = 42
            def func(a: {1, d}) -> (lambda c: e): pass
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_annotationUndefined|  s    c         C   s   |  j  d  d  S(   NsR   
        from abc import ABCMeta
        class A(metaclass=ABCMeta): pass
        (   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_metaClassUndefined  s    c         C   s   |  j  d  |  j  d  d S(   sc   
        Using the loop variable of a generator expression results in no
        warnings.
        s   (a for a in [1, 2, 3] if a)s-   (b for b in (a for a in [1, 2, 3] if a) if b)N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_definedInGenExp  s    c         C   s*   |  j  d t j  |  j  d t j  d S(   s}   
        The loop variables of generator expressions nested together are
        not defined in the other generator.
        s-   (b for b in (a for a in [1, 2, 3] if b) if b)s-   (b for b in (a for a in [1, 2, 3] if a) if a)N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_undefinedInGenExpNested  s    	
	c         C   sD   |  j  d  |  j  d  |  j  d t j  |  j  d t j  d S(   sr   
        Some compatibility code checks explicitly for NameError.
        It should not trigger warnings.
        sc   
        try:
            socket_map
        except NameError:
            socket_map = {}
        s   
        try:
            _memoryview.contiguous
        except (NameError, AttributeError):
            raise RuntimeError("Python >= 3.3 is required")
        sY   
        try:
            socket_map
        except:
            socket_map = {}
        sc   
        try:
            socket_map
        except Exception:
            socket_map = {}
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_undefinedWithErrorHandler  s    c         C   s-   |  j  d  t d k r) |  j  d  n  d S(   sT   
        Defined name for generator expressions and dict/set comprehension.
        s   
        class A:
            T = range(10)

            Z = (x for x in T)
            L = [x for x in T]
            B = dict((i, str(i)) for i in T)
        i   i   s   
            class A:
                T = range(10)

                X = {x for x in T}
                Y = {x:x for x in T}
            N(   i   i   (   R	   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_definedInClass  s
    c         C   s   |  j  d  d S(   s9   Defined name for nested generator expressions in a class.sa   
        class A:
            T = range(10)

            Z = (x for x in (a for a in T))
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_definedInClassNested  s    c         C   s=   |  j  d t j  |  j  d t j  |  j  d t j  d S(   sP   
        The loop variable is defined after the expression is computed.
        s9   
        for i in range(i):
            print(i)
        s(   
        [42 for i in range(i)]
        s(   
        (42 for i in range(i))
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_undefinedInLoop  s    i   i   s&   Dictionary comprehensions do not existc         C   s   |  j  d  d S(   si   
        Defined name referenced from a lambda function within a dict/set
        comprehension.
        s4   
        {lambda: id(x) for x in range(10)}
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt/   test_definedFromLambdaInDictionaryComprehension  s    c         C   s   |  j  d  d S(   sg   
        Defined name referenced from a lambda function within a generator
        expression.
        s7   
        any(lambda: id(x) for x in range(10))
        N(   R	   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt!   test_definedFromLambdaInGenerator  s    c         C   s   |  j  d t j  d S(   sk   
        Undefined name referenced from a lambda function within a dict/set
        comprehension.
        s4   
        {lambda: id(y) for x in range(10)}
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt1   test_undefinedFromLambdaInDictionaryComprehension  s    c         C   s   |  j  d t j  d S(   si   
        Undefined name referenced from a lambda function within a generator
        expression.
        s7   
        any(lambda: id(y) for x in range(10))
        N(   R	   R
   R   (   R   (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt'   test_undefinedFromLambdaInComprehension  s    (   i   (   i   (   i   (   i   (   i   (   i   (   i   (   i   (   i   (   i   (   i   (   i   (   i   i   (   i   i   (E   R$   t
   __module__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/   R0   R1   R2   R4   R5   R6   R7   R8   R9   R:   R;   R<   R=   R>   R?   R@   RG   RH   RJ   RK   RL   RM   RN   RO   RP   RQ   RR   RS   RT   RU   RV   RW   RX   RY   RZ   R[   R\   R]   R^   (    (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyR   	   s   																					
			
																									
		
t	   NameTestsc           B   s   e  Z d  Z d   Z RS(   s6   
    Tests for some extra cases of name handling.
    c         C   sI   t  d d d t  } t   | j d j d _ |  j t t j	 |  d S(   sj   
        A Name node with an unrecognized context results in a RuntimeError being
        raised.
        s   x = 10s   <test>t   execi    N(
   t   compileR    t   objectt   bodyt   targetst   ctxt   assertRaisest   RuntimeErrorR   t   Checker(   R   t   tree(    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   test_impossibleContext  s    (   R$   R_   t   __doc__Rk   (    (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyR`     s   N(   t   _astR    t   sysR   t   pyflakesR   R
   R   t   pyflakes.test.harnessR   R   R   R   R`   (    (    (    sD   /tmp/pip-build-EndXZ2/pyflakes/pyflakes/test/test_undefined_names.pyt   <module>   s      