Repository: xonsh/xonsh

Issue:
xonsh function 'args' not in namespace
the following script:

```
def ttest(*args):
    if not args:
        print("NOPE")
    else:
        print("OKAY")

ttest()
```

when run with xonsh it results in:

```
Traceback (most recent call last):
  File "/home/laerus/projects/xonsh/xonsh/built_ins.py", line 513, in run_subproc
    **subproc_kwargs)
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'args:'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/laerus/projects/xonsh/xonsh/__main__.py", line 2, in <module>
    main()
  File "/home/laerus/projects/xonsh/xonsh/main.py", line 233, in main
    loc=None, mode='exec')
  File "/home/laerus/projects/xonsh/xonsh/codecache.py", line 145, in run_script_with_cache
    run_compiled_code(ccode, glb, loc, mode)
  File "/home/laerus/projects/xonsh/xonsh/codecache.py", line 65, in run_compiled_code
    func(code, glb, loc)
  File "tt.xsh", line 7, in <module>
    ttest()
  File "tt.xsh", line 2, in ttest
    if not args:
  File "/home/laerus/projects/xonsh/xonsh/built_ins.py", line 650, in subproc_captured_hiddenobject
    return run_subproc(cmds, captured='hiddenobject')
  File "/home/laerus/projects/xonsh/xonsh/built_ins.py", line 523, in run_subproc
    raise XonshError(e)
xonsh.tools.XonshError: xonsh: subprocess mode: command not found: args:
Did you mean the following?
    xargs:  Command (/usr/bin/xargs)

args:: command not found
```



Discussion:
Thanks for reporting @laerus. I think I know generally what is causing this.  Can you try running this in debug mode please?

And reporting the full output, of course

```
$ python3 -m xonsh tt.xsh
PLY: PARSE DEBUG START

State  : 0
Stack  : . LexToken(NAME,'python3',1,0)
Action : Shift and goto state 39

State  : 39
Stack  : NAME . LexToken(MINUS,'-',1,8)
Action : Reduce rule [name_tok -> NAME] with ['python3'] and goto state 140
Result : <LexToken @ 0x7eff70f550f0> (LexToken(NAME,'python3',1,0))

State  : 140
Stack  : name_tok . LexToken(MINUS,'-',1,8)
Action : Reduce rule [atom -> name_tok] with [<LexToken @ 0x7eff70f550f0>] and goto state 15
Result : <Name @ 0x7eff70fafc50> (<_ast.Name object at 0x7eff70fafc50>)

State  : 15
Stack  : atom . LexToken(MINUS,'-',1,8)
Action : Reduce rule [empty -> <empty>] with [] and goto state 169
Result : <NoneType @ 0xa410c0> (None)

State  : 169
Stack  : atom empty . LexToken(MINUS,'-',1,8)
Action : Reduce rule [trailer_list_opt -> empty] with [None] and goto state 173
Result : <NoneType @ 0xa410c0> (None)

State  : 173
Stack  : atom trailer_list_opt . LexToken(MINUS,'-',1,8)
Action : Reduce rule [atom_expr -> atom trailer_list_opt] with [<Name @ 0x7eff70fafc50>,None] and goto state 121
Result : <Name @ 0x7eff70fafc50> (<_ast.Name object at 0x7eff70fafc50>)

State  : 121
Stack  : atom_expr . LexToken(MINUS,'-',1,8)
Action : Reduce rule [power -> atom_expr] with [<Name @ 0x7eff70fafc50>] and goto state 83
Result : <Name @ 0x7eff70fafc50> (<_ast.Name object at 0x7eff70fafc50>)

State  : 83
Stack  : power . LexToken(MINUS,'-',1,8)
Action : Reduce rule [factor -> power] with [<Name @ 0x7eff70fafc50>] and goto state 96
Result : <Name @ 0x7eff70fafc50> (<_ast.Name object at 0x7eff70fafc50>)

State  : 96
Stack  : factor . LexToken(MINUS,'-',1,8)
Action : Reduce rule [empty -> <empty>] with [] and goto state 326
Result : <NoneType @ 0xa410c0> (None)

State  : 326
Stack  : factor empty . LexToken(MINUS,'-',1,8)
Action : Reduce rule [op_factor_list_opt -> empty] with [None] and goto state 331
Result : <NoneType @ 0xa410c0> (None)

State  : 331
Stack  : factor op_factor_list_opt . LexToken(MINUS,'-',1,8)
Action : Reduce rule [term -> factor op_factor_list_opt] with [<Name @ 0x7eff70fafc50>,None] and goto state 60
Result : <Name @ 0x7eff70fafc50> (<_ast.Name object at 0x7eff70fafc50>)

State  : 60
Stack  : term . LexToken(MINUS,'-',1,8)
Action : Shift and goto state 275

State  : 275
Stack  : term MINUS . LexToken(NAME,'m',1,9)
Action : Reduce rule [minus_tok -> MINUS] with ['-'] and goto state 273
Result : <LexToken @ 0x7eff70f55c88> (LexToken(MINUS,'-',1,8))

State  : 273
Stack  : term minus_tok . LexToken(NAME,'m',1,9)
Action : Shift and goto state 39

State  : 39
Stack  : term minus_tok NAME . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [name_tok -> NAME] with ['m'] and goto state 140
Result : <LexToken @ 0x7eff70f550f0> (LexToken(NAME,'m',1,9))

State  : 140
Stack  : term minus_tok name_tok . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [atom -> name_tok] with [<LexToken @ 0x7eff70f550f0>] and goto state 15
Result : <Name @ 0x7eff70fcc128> (<_ast.Name object at 0x7eff70fcc128>)

State  : 15
Stack  : term minus_tok atom . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [empty -> <empty>] with [] and goto state 169
Result : <NoneType @ 0xa410c0> (None)

State  : 169
Stack  : term minus_tok atom empty . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [trailer_list_opt -> empty] with [None] and goto state 173
Result : <NoneType @ 0xa410c0> (None)

State  : 173
Stack  : term minus_tok atom trailer_list_opt . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [atom_expr -> atom trailer_list_opt] with [<Name @ 0x7eff70fcc128>,None] and goto state 121
Result : <Name @ 0x7eff70fcc128> (<_ast.Name object at 0x7eff70fcc128>)

State  : 121
Stack  : term minus_tok atom_expr . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [power -> atom_expr] with [<Name @ 0x7eff70fcc128>] and goto state 83
Result : <Name @ 0x7eff70fcc128> (<_ast.Name object at 0x7eff70fcc128>)

State  : 83
Stack  : term minus_tok power . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [factor -> power] with [<Name @ 0x7eff70fcc128>] and goto state 96
Result : <Name @ 0x7eff70fcc128> (<_ast.Name object at 0x7eff70fcc128>)

State  : 96
Stack  : term minus_tok factor . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [empty -> <empty>] with [] and goto state 326
Result : <NoneType @ 0xa410c0> (None)

State  : 326
Stack  : term minus_tok factor empty . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [op_factor_list_opt -> empty] with [None] and goto state 331
Result : <NoneType @ 0xa410c0> (None)

State  : 331
Stack  : term minus_tok factor op_factor_list_opt . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [term -> factor op_factor_list_opt] with [<Name @ 0x7eff70fcc128>,None] and goto state 466
Result : <Name @ 0x7eff70fcc128> (<_ast.Name object at 0x7eff70fcc128>)

State  : 466
Stack  : term minus_tok term . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [pm_term -> minus_tok term] with [<LexToken @ 0x7eff70f55c88>,<Name @ 0x7eff70fcc128>] and goto state 276
Result : <list @ 0x7eff70c791c8> ([<_ast.Sub object at 0x7eff70fcc6a0>, <_ ...)

State  : 276
Stack  : term pm_term . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [pm_term_list -> pm_term] with [<list @ 0x7eff70c791c8>] and goto state 271
Result : <list @ 0x7eff70c791c8> ([<_ast.Sub object at 0x7eff70fcc6a0>, <_ ...)

State  : 271
Stack  : term pm_term_list . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [arith_expr -> term pm_term_list] with [<Name @ 0x7eff70fafc50>,<list @ 0x7eff70c791c8>] and goto state 141
Result : <BinOp @ 0x7eff70f55c88> (<_ast.BinOp object at 0x7eff70f55c88>)

State  : 141
Stack  : arith_expr . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [empty -> <empty>] with [] and goto state 387
Result : <NoneType @ 0xa410c0> (None)

State  : 387
Stack  : arith_expr empty . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [shift_arith_expr_list_opt -> empty] with [None] and goto state 390
Result : <NoneType @ 0xa410c0> (None)

State  : 390
Stack  : arith_expr shift_arith_expr_list_opt . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [shift_expr -> arith_expr shift_arith_expr_list_opt] with [<BinOp @ 0x7eff70f55c88>,None] and goto state 77
Result : <BinOp @ 0x7eff70f55c88> (<_ast.BinOp object at 0x7eff70f55c88>)

State  : 77
Stack  : shift_expr . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [empty -> <empty>] with [] and goto state 298
Result : <NoneType @ 0xa410c0> (None)

State  : 298
Stack  : shift_expr empty . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [ampersand_shift_expr_list_opt -> empty] with [None] and goto state 300
Result : <NoneType @ 0xa410c0> (None)

State  : 300
Stack  : shift_expr ampersand_shift_expr_list_opt . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [and_expr -> shift_expr ampersand_shift_expr_list_opt] with [<BinOp @ 0x7eff70f55c88>,None] and goto state 75
Result : <BinOp @ 0x7eff70f55c88> (<_ast.BinOp object at 0x7eff70f55c88>)

State  : 75
Stack  : and_expr . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [empty -> <empty>] with [] and goto state 293
Result : <NoneType @ 0xa410c0> (None)

State  : 293
Stack  : and_expr empty . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [xor_and_expr_list_opt -> empty] with [None] and goto state 297
Result : <NoneType @ 0xa410c0> (None)

State  : 297
Stack  : and_expr xor_and_expr_list_opt . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [xor_expr -> and_expr xor_and_expr_list_opt] with [<BinOp @ 0x7eff70f55c88>,None] and goto state 29
Result : <BinOp @ 0x7eff70f55c88> (<_ast.BinOp object at 0x7eff70f55c88>)

State  : 29
Stack  : xor_expr . LexToken(NAME,'xonsh',1,11)
Action : Reduce rule [expr -> xor_expr] with [<BinOp @ 0x7eff70f55c88>] and goto state 18
Result : <BinOp @ 0x7eff70f55c88> (<_ast.BinOp object at 0x7eff70f55c88>)

State  : 18
Stack  : expr . LexToken(NAME,'xonsh',1,11)
ERROR: Error  : expr . LexToken(NAME,'xonsh',1,11)
<xonsh-code>:1:11 - python3 -m xonsh tt.xsh
<xonsh-code>:1:11 + ![python3 -m xonsh tt.xsh]
PLY: PARSE DEBUG START

State  : 0
Stack  : . LexToken(BANG_LBRACKET,'![',1,0)
Action : Shift and goto state 99

State  : 99
Stack  : BANG_LBRACKET . LexToken(NAME,'python3',1,2)
Action : Reduce rule [bang_lbracket_tok -> BANG_LBRACKET] with ['!['] and goto state 26
Result : <LexToken @ 0x7eff70fcc588> (LexToken(BANG_LBRACKET,'![',1,0))

State  : 26
Stack  : bang_lbracket_tok . LexToken(NAME,'python3',1,2)
Action : Shift and goto state 236

State  : 236
Stack  : bang_lbracket_tok NAME . LexToken(WS,' ',1,9)
Action : Reduce rule [subproc_arg_part -> NAME] with ['python3'] and goto state 204
Result : <str @ 0x7eff70fcc6c0> ('python3')

State  : 204
Stack  : bang_lbracket_tok subproc_arg_part . LexToken(WS,' ',1,9)
Action : Reduce rule [subproc_arg -> subproc_arg_part] with ['python3'] and goto state 213
Result : <str @ 0x7eff70fcc6c0> ('python3')

State  : 213
Stack  : bang_lbracket_tok subproc_arg . LexToken(WS,' ',1,9)
Action : Reduce rule [subproc_atom -> subproc_arg] with ['python3'] and goto state 211
Result : <Call @ 0x7eff70fcc438> (<_ast.Call object at 0x7eff70fcc438>)

State  : 211
Stack  : bang_lbracket_tok subproc_atom . LexToken(WS,' ',1,9)
Action : Reduce rule [subproc_atoms -> subproc_atom] with [<Call @ 0x7eff70fcc438>] and goto state 216
Result : <list @ 0x7eff70c6dfc8> ([<_ast.Call object at 0x7eff70fcc438>])

State  : 216
Stack  : bang_lbracket_tok subproc_atoms . LexToken(WS,' ',1,9)
Action : Shift and goto state 432

State  : 432
Stack  : bang_lbracket_tok subproc_atoms WS . LexToken(MINUS,'-',1,10)
Action : Shift and goto state 208

State  : 208
Stack  : bang_lbracket_tok subproc_atoms WS MINUS . LexToken(NAME,'m',1,11)
Action : Reduce rule [subproc_arg_part -> MINUS] with ['-'] and goto state 204
Result : <str @ 0x7eff7584dd18> ('-')

State  : 204
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg_part . LexToken(NAME,'m',1,11)
Action : Reduce rule [subproc_arg -> subproc_arg_part] with ['-'] and goto state 213
Result : <str @ 0x7eff7584dd18> ('-')

State  : 213
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg . LexToken(NAME,'m',1,11)
Action : Shift and goto state 236

State  : 236
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg NAME . LexToken(WS,' ',1,12)
Action : Reduce rule [subproc_arg_part -> NAME] with ['m'] and goto state 431
Result : <str @ 0x7eff7586a6c0> ('m')

State  : 431
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg subproc_arg_part . LexToken(WS,' ',1,12)
Action : Reduce rule [subproc_arg -> subproc_arg subproc_arg_part] with ['-','m'] and goto state 213
Result : <str @ 0x7eff70fcc2d0> ('-m')

State  : 213
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg . LexToken(WS,' ',1,12)
Action : Reduce rule [subproc_atom -> subproc_arg] with ['-m'] and goto state 586
Result : <Call @ 0x7eff70f3a898> (<_ast.Call object at 0x7eff70f3a898>)

State  : 586
Stack  : bang_lbracket_tok subproc_atoms WS subproc_atom . LexToken(WS,' ',1,12)
Action : Reduce rule [subproc_atoms -> subproc_atoms WS subproc_atom] with [<list @ 0x7eff70c6dfc8>,' ',<Call @ 0x7eff70f3a898>] and goto state 216
Result : <list @ 0x7eff70c6dfc8> ([<_ast.Call object at 0x7eff70fcc438>, < ...)

State  : 216
Stack  : bang_lbracket_tok subproc_atoms . LexToken(WS,' ',1,12)
Action : Shift and goto state 432

State  : 432
Stack  : bang_lbracket_tok subproc_atoms WS . LexToken(NAME,'xonsh',1,13)
Action : Shift and goto state 236

State  : 236
Stack  : bang_lbracket_tok subproc_atoms WS NAME . LexToken(WS,' ',1,18)
Action : Reduce rule [subproc_arg_part -> NAME] with ['xonsh'] and goto state 204
Result : <str @ 0x7eff70fcc928> ('xonsh')

State  : 204
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg_part . LexToken(WS,' ',1,18)
Action : Reduce rule [subproc_arg -> subproc_arg_part] with ['xonsh'] and goto state 213
Result : <str @ 0x7eff70fcc928> ('xonsh')

State  : 213
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg . LexToken(WS,' ',1,18)
Action : Reduce rule [subproc_atom -> subproc_arg] with ['xonsh'] and goto state 586
Result : <Call @ 0x7eff70f3aba8> (<_ast.Call object at 0x7eff70f3aba8>)

State  : 586
Stack  : bang_lbracket_tok subproc_atoms WS subproc_atom . LexToken(WS,' ',1,18)
Action : Reduce rule [subproc_atoms -> subproc_atoms WS subproc_atom] with [<list @ 0x7eff70c6dfc8>,' ',<Call @ 0x7eff70f3aba8>] and goto state 216
Result : <list @ 0x7eff70c6dfc8> ([<_ast.Call object at 0x7eff70fcc438>, < ...)

State  : 216
Stack  : bang_lbracket_tok subproc_atoms . LexToken(WS,' ',1,18)
Action : Shift and goto state 432

State  : 432
Stack  : bang_lbracket_tok subproc_atoms WS . LexToken(NAME,'tt',1,19)
Action : Shift and goto state 236

State  : 236
Stack  : bang_lbracket_tok subproc_atoms WS NAME . LexToken(PERIOD,'.',1,21)
Action : Reduce rule [subproc_arg_part -> NAME] with ['tt'] and goto state 204
Result : <str @ 0x7eff70fcc458> ('tt')

State  : 204
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg_part . LexToken(PERIOD,'.',1,21)
Action : Reduce rule [subproc_arg -> subproc_arg_part] with ['tt'] and goto state 213
Result : <str @ 0x7eff70fcc458> ('tt')

State  : 213
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg . LexToken(PERIOD,'.',1,21)
Action : Shift and goto state 222

State  : 222
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg PERIOD . LexToken(NAME,'xsh',1,22)
Action : Reduce rule [subproc_arg_part -> PERIOD] with ['.'] and goto state 431
Result : <str @ 0x7eff75878068> ('.')

State  : 431
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg subproc_arg_part . LexToken(NAME,'xsh',1,22)
Action : Reduce rule [subproc_arg -> subproc_arg subproc_arg_part] with ['tt','.'] and goto state 213
Result : <str @ 0x7eff70f3af80> ('tt.')

State  : 213
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg . LexToken(NAME,'xsh',1,22)
Action : Shift and goto state 236

State  : 236
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg NAME . LexToken(RBRACKET,']',1,25)
Action : Reduce rule [subproc_arg_part -> NAME] with ['xsh'] and goto state 431
Result : <str @ 0x7eff70fcc378> ('xsh')

State  : 431
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg subproc_arg_part . LexToken(RBRACKET,']',1,25)
Action : Reduce rule [subproc_arg -> subproc_arg subproc_arg_part] with ['tt.','xsh'] and goto state 213
Result : <str @ 0x7eff70fcc458> ('tt.xsh')

State  : 213
Stack  : bang_lbracket_tok subproc_atoms WS subproc_arg . LexToken(RBRACKET,']',1,25)
Action : Reduce rule [subproc_atom -> subproc_arg] with ['tt.xsh'] and goto state 586
Result : <Call @ 0x7eff70f3ad30> (<_ast.Call object at 0x7eff70f3ad30>)

State  : 586
Stack  : bang_lbracket_tok subproc_atoms WS subproc_atom . LexToken(RBRACKET,']',1,25)
Action : Reduce rule [subproc_atoms -> subproc_atoms WS subproc_atom] with [<list @ 0x7eff70c6dfc8>,' ',<Call @ 0x7eff70f3ad30>] and goto state 216
Result : <list @ 0x7eff70c6dfc8> ([<_ast.Call object at 0x7eff70fcc438>, < ...)

State  : 216
Stack  : bang_lbracket_tok subproc_atoms . LexToken(RBRACKET,']',1,25)
Action : Reduce rule [subproc -> subproc_atoms] with [<list @ 0x7eff70c6dfc8>] and goto state 228
Result : <list @ 0x7eff70c74f88> ([<_ast.List object at 0x7eff70f3a9b0>])

State  : 228
Stack  : bang_lbracket_tok subproc . LexToken(RBRACKET,']',1,25)
Action : Shift and goto state 439

State  : 439
Stack  : bang_lbracket_tok subproc RBRACKET . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [atom -> bang_lbracket_tok subproc RBRACKET] with [<LexToken @ 0x7eff70fcc588>,<list @ 0x7eff70c74f88>,']'] and goto state 15
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 15
Stack  : atom . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [empty -> <empty>] with [] and goto state 169
Result : <NoneType @ 0xa410c0> (None)

State  : 169
Stack  : atom empty . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [trailer_list_opt -> empty] with [None] and goto state 173
Result : <NoneType @ 0xa410c0> (None)

State  : 173
Stack  : atom trailer_list_opt . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [atom_expr -> atom trailer_list_opt] with [<Call @ 0x7eff70f3a390>,None] and goto state 121
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 121
Stack  : atom_expr . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [power -> atom_expr] with [<Call @ 0x7eff70f3a390>] and goto state 83
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 83
Stack  : power . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [factor -> power] with [<Call @ 0x7eff70f3a390>] and goto state 96
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 96
Stack  : factor . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [empty -> <empty>] with [] and goto state 326
Result : <NoneType @ 0xa410c0> (None)

State  : 326
Stack  : factor empty . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [op_factor_list_opt -> empty] with [None] and goto state 331
Result : <NoneType @ 0xa410c0> (None)

State  : 331
Stack  : factor op_factor_list_opt . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [term -> factor op_factor_list_opt] with [<Call @ 0x7eff70f3a390>,None] and goto state 60
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 60
Stack  : term . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [arith_expr -> term] with [<Call @ 0x7eff70f3a390>] and goto state 141
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 141
Stack  : arith_expr . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [empty -> <empty>] with [] and goto state 387
Result : <NoneType @ 0xa410c0> (None)

State  : 387
Stack  : arith_expr empty . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [shift_arith_expr_list_opt -> empty] with [None] and goto state 390
Result : <NoneType @ 0xa410c0> (None)

State  : 390
Stack  : arith_expr shift_arith_expr_list_opt . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [shift_expr -> arith_expr shift_arith_expr_list_opt] with [<Call @ 0x7eff70f3a390>,None] and goto state 77
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 77
Stack  : shift_expr . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [empty -> <empty>] with [] and goto state 298
Result : <NoneType @ 0xa410c0> (None)

State  : 298
Stack  : shift_expr empty . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [ampersand_shift_expr_list_opt -> empty] with [None] and goto state 300
Result : <NoneType @ 0xa410c0> (None)

State  : 300
Stack  : shift_expr ampersand_shift_expr_list_opt . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [and_expr -> shift_expr ampersand_shift_expr_list_opt] with [<Call @ 0x7eff70f3a390>,None] and goto state 75
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 75
Stack  : and_expr . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [empty -> <empty>] with [] and goto state 293
Result : <NoneType @ 0xa410c0> (None)

State  : 293
Stack  : and_expr empty . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [xor_and_expr_list_opt -> empty] with [None] and goto state 297
Result : <NoneType @ 0xa410c0> (None)

State  : 297
Stack  : and_expr xor_and_expr_list_opt . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [xor_expr -> and_expr xor_and_expr_list_opt] with [<Call @ 0x7eff70f3a390>,None] and goto state 29
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 29
Stack  : xor_expr . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [expr -> xor_expr] with [<Call @ 0x7eff70f3a390>] and goto state 18
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 18
Stack  : expr . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [empty -> <empty>] with [] and goto state 185
Result : <NoneType @ 0xa410c0> (None)

State  : 185
Stack  : expr empty . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [comp_op_expr_list_opt -> empty] with [None] and goto state 188
Result : <NoneType @ 0xa410c0> (None)

State  : 188
Stack  : expr comp_op_expr_list_opt . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [comparison -> expr comp_op_expr_list_opt] with [<Call @ 0x7eff70f3a390>,None] and goto state 58
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 58
Stack  : comparison . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [not_test -> comparison] with [<Call @ 0x7eff70f3a390>] and goto state 37
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 37
Stack  : not_test . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [empty -> <empty>] with [] and goto state 241
Result : <NoneType @ 0xa410c0> (None)

State  : 241
Stack  : not_test empty . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [and_not_test_list_opt -> empty] with [None] and goto state 242
Result : <NoneType @ 0xa410c0> (None)

State  : 242
Stack  : not_test and_not_test_list_opt . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [and_test -> not_test and_not_test_list_opt] with [<Call @ 0x7eff70f3a390>,None] and goto state 70
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 70
Stack  : and_test . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [empty -> <empty>] with [] and goto state 285
Result : <NoneType @ 0xa410c0> (None)

State  : 285
Stack  : and_test empty . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [or_and_test_list_opt -> empty] with [None] and goto state 283
Result : <NoneType @ 0xa410c0> (None)

State  : 283
Stack  : and_test or_and_test_list_opt . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [or_test -> and_test or_and_test_list_opt] with [<Call @ 0x7eff70f3a390>,None] and goto state 14
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 14
Stack  : or_test . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [test -> or_test] with [<Call @ 0x7eff70f3a390>] and goto state 82
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 82
Stack  : test . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [test_or_star_expr -> test] with [<Call @ 0x7eff70f3a390>] and goto state 91
Result : <Call @ 0x7eff70f3a390> (<_ast.Call object at 0x7eff70f3a390>)

State  : 91
Stack  : test_or_star_expr . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [empty -> <empty>] with [] and goto state 312
Result : <NoneType @ 0xa410c0> (None)

State  : 312
Stack  : test_or_star_expr empty . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [comma_opt -> empty] with [None] and goto state 310
Result : <NoneType @ 0xa410c0> (None)

State  : 310
Stack  : test_or_star_expr comma_opt . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [testlist_star_expr -> test_or_star_expr comma_opt] with [<Call @ 0x7eff70f3a390>,None] and goto state 128
Result : <list @ 0x7eff70ee3448> ([<_ast.Call object at 0x7eff70f3a390>])

State  : 128
Stack  : testlist_star_expr . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [empty -> <empty>] with [] and goto state 359
Result : <NoneType @ 0xa410c0> (None)

State  : 359
Stack  : testlist_star_expr empty . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [equals_yield_expr_or_testlist_list_opt -> empty] with [None] and goto state 364
Result : <NoneType @ 0xa410c0> (None)

State  : 364
Stack  : testlist_star_expr equals_yield_expr_or_testlist_list_opt . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [expr_stmt -> testlist_star_expr equals_yield_expr_or_testlist_list_opt] with [<list @ 0x7eff70ee3448>,None] and goto state 69
Result : <Expr @ 0x7eff70fcc588> (<_ast.Expr object at 0x7eff70fcc588>)

State  : 69
Stack  : expr_stmt . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [small_stmt -> expr_stmt] with [<Expr @ 0x7eff70fcc588>] and goto state 95
Result : <Expr @ 0x7eff70fcc588> (<_ast.Expr object at 0x7eff70fcc588>)

State  : 95
Stack  : small_stmt . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [empty -> <empty>] with [] and goto state 321
Result : <NoneType @ 0xa410c0> (None)

State  : 321
Defaulted state 321: Reduce using 265
Stack  : small_stmt empty . LexToken(NEWLINE,'\n',1,26)
Action : Reduce rule [semi_opt -> empty] with [None] and goto state 318
Result : <NoneType @ 0xa410c0> (None)

State  : 318
Stack  : small_stmt semi_opt . LexToken(NEWLINE,'\n',1,26)
Action : Shift and goto state 491

State  : 491
Stack  : small_stmt semi_opt NEWLINE . $end
Action : Reduce rule [simple_stmt -> small_stmt semi_opt NEWLINE] with [<Expr @ 0x7eff70fcc588>,None,'\n'] and goto state 30
Result : <list @ 0x7eff70c6dfc8> ([<_ast.Expr object at 0x7eff70fcc588>])

State  : 30
Stack  : simple_stmt . $end
Action : Reduce rule [stmt -> simple_stmt] with [<list @ 0x7eff70c6dfc8>] and goto state 57
Result : <list @ 0x7eff70c6dfc8> ([<_ast.Expr object at 0x7eff70fcc588>])

State  : 57
Stack  : stmt . $end
Action : Reduce rule [newline_or_stmt -> stmt] with [<list @ 0x7eff70c6dfc8>] and goto state 36
Result : <list @ 0x7eff70c6dfc8> ([<_ast.Expr object at 0x7eff70fcc588>])

State  : 36
Stack  : newline_or_stmt . $end
Action : Reduce rule [file_stmts -> newline_or_stmt] with [<list @ 0x7eff70c6dfc8>] and goto state 62
Result : <list @ 0x7eff70c6dfc8> ([<_ast.Expr object at 0x7eff70fcc588>])

State  : 62
Stack  : file_stmts . $end
Action : Reduce rule [file_input -> file_stmts] with [<list @ 0x7eff70c6dfc8>] and goto state 125
Result : <Module @ 0x7eff70f550f0> (<_ast.Module object at 0x7eff70f550f0>)

State  : 125
Defaulted state 125: Reduce using 210
Stack  : file_input . $end
Action : Reduce rule [start_symbols -> file_input] with [<Module @ 0x7eff70f550f0>] and goto state 119
Result : <Module @ 0x7eff70f550f0> (<_ast.Module object at 0x7eff70f550f0>)

State  : 119
Stack  : start_symbols . $end
Done   : Returning <Module @ 0x7eff70f550f0> (<_ast.Module object at 0x7eff70f550f0>)
PLY: PARSE DEBUG END
Traceback (most recent call last):
  File "/home/laerus/projects/xonsh/xonsh/built_ins.py", line 513, in run_subproc
    **subproc_kwargs)
  File "/usr/lib/python3.5/subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.5/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'args:'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/laerus/projects/xonsh/xonsh/__main__.py", line 2, in <module>
    main()
  File "/home/laerus/projects/xonsh/xonsh/main.py", line 233, in main
    loc=None, mode='exec')
  File "/home/laerus/projects/xonsh/xonsh/codecache.py", line 145, in run_script_with_cache
    run_compiled_code(ccode, glb, loc, mode)
  File "/home/laerus/projects/xonsh/xonsh/codecache.py", line 65, in run_compiled_code
    func(code, glb, loc)
  File "tt.xsh", line 7, in <module>
    ttest()
  File "tt.xsh", line 2, in ttest
    if not args:
  File "/home/laerus/projects/xonsh/xonsh/built_ins.py", line 650, in subproc_captured_hiddenobject
    return run_subproc(cmds, captured='hiddenobject')
  File "/home/laerus/projects/xonsh/xonsh/built_ins.py", line 523, in run_subproc
    raise XonshError(e)
xonsh.tools.XonshError: xonsh: subprocess mode: command not found: args:
Did you mean the following?
    xargs:  Command (/usr/bin/xargs)

args:: command not found
```


Resolving patch:
diff --git a/xonsh/ast.py b/xonsh/ast.py
--- a/xonsh/ast.py
+++ b/xonsh/ast.py
@@ -431,6 +431,13 @@ def visit_FunctionDef(self, node):
         """Handle visiting a function definition."""
         self.ctxadd(node.name)
         self.contexts.append(set())
+        args = node.args
+        argchain = [args.args, args.kwonlyargs]
+        if args.vararg is not None:
+            argchain.append((args.vararg,))
+        if args.kwarg is not None:
+            argchain.append((args.kwarg,))
+        self.ctxupdate(a.arg for a in itertools.chain.from_iterable(argchain))
         self.generic_visit(node)
         self.contexts.pop()
         return node


Test patch:
diff --git a/tests/test_ast.py b/tests/test_ast.py
--- a/tests/test_ast.py
+++ b/tests/test_ast.py
@@ -1,10 +1,12 @@
 """Xonsh AST tests."""
+import ast as pyast
+
 from xonsh import ast
 from xonsh.ast import Tuple, Name, Store, min_line
 
 import pytest
 
-from tools import  check_parse
+from tools import check_parse, nodes_equal
 
 
 @pytest.fixture(autouse=True)
@@ -31,3 +33,40 @@ def test_multilline_num():
     tree = check_parse(code)
     lsnode = tree.body[1]
     assert 2 == min_line(lsnode)
+
+
+@pytest.mark.parametrize('inp', [
+"""def f():
+    if True:
+        pass
+""",
+"""def f(x):
+    if x:
+        pass
+""",
+"""def f(*args):
+    if not args:
+        pass
+""",
+"""def f(*, y):
+    if y:
+        pass
+""",
+"""def f(**kwargs):
+    if not kwargs:
+        pass
+""",
+"""def f(k=42):
+    if not k:
+        pass
+""",
+"""def f(k=10, *, a, b=1, **kw):
+    if not kw and b:
+        pass
+""",
+])
+def test_args_in_scope(inp):
+    # Context sensitive parsing should not modify AST
+    exp = pyast.parse(inp)
+    obs = check_parse(inp)
+    assert nodes_equal(exp, obs)
diff --git a/tests/test_parser.py b/tests/test_parser.py
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -10,7 +10,7 @@
 from xonsh.ast import pdump
 from xonsh.parser import Parser
 
-from tools import VER_FULL, skip_if_py34
+from tools import VER_FULL, skip_if_py34, nodes_equal
 
 # a lot of col_offset data changed from Py v3.5.0 -> v3.5.1
 INC_ATTRS = (3, 5, 1) <= VER_FULL
@@ -24,22 +24,6 @@ def xonsh_builtins_autouse(xonsh_builtins):
                 yacc_table='parser_test_table')
 
 
-def nodes_equal(x, y):
-    __tracebackhide__ = True
-    assert type(x) == type(y)
-    if isinstance(x, (ast.Expr, ast.FunctionDef, ast.ClassDef)):
-        assert x.lineno == y.lineno
-        assert x.col_offset == y.col_offset
-    for (xname, xval), (yname, yval) in zip(ast.iter_fields(x),
-                                            ast.iter_fields(y)):
-        assert xname == yname
-        assert type(xval) == type(yval)
-    for xchild, ychild in zip(ast.iter_child_nodes(x),
-                              ast.iter_child_nodes(y)):
-        assert nodes_equal(xchild, ychild)
-    return True
-
-
 def check_ast(inp, run=True, mode='eval'):
     __tracebackhide__ = True
     # expect a Python AST
diff --git a/tests/tools.py b/tests/tools.py
--- a/tests/tools.py
+++ b/tests/tools.py
@@ -2,6 +2,7 @@
 """Tests the xonsh lexer."""
 from __future__ import unicode_literals, print_function
 import sys
+import ast
 import builtins
 import platform
 import subprocess
@@ -85,3 +86,23 @@ def check_eval(input):
 def check_parse(input):
     tree = builtins.__xonsh_execer__.parse(input, ctx=None)
     return tree
+
+#
+# Parser tools
+#
+
+
+def nodes_equal(x, y):
+    __tracebackhide__ = True
+    assert type(x) == type(y)
+    if isinstance(x, (ast.Expr, ast.FunctionDef, ast.ClassDef)):
+        assert x.lineno == y.lineno
+        assert x.col_offset == y.col_offset
+    for (xname, xval), (yname, yval) in zip(ast.iter_fields(x),
+                                            ast.iter_fields(y)):
+        assert xname == yname
+        assert type(xval) == type(yval)
+    for xchild, ychild in zip(ast.iter_child_nodes(x),
+                              ast.iter_child_nodes(y)):
+        assert nodes_equal(xchild, ychild)
+    return True