Repository: xonsh/xonsh

Issue:
'TypeError: required field "posonlyargs" missing from arguments' when defining function in xonsh on python 3.8
## xonfig
```
+------------------+---------------------+
| xonsh            | 0.9.10              |
| Git SHA          | c6e168ff            |
| Commit Date      | Aug 9 15:03:58 2019 |
| Python           | 3.8.0               |
| PLY              | 3.11                |
| have readline    | True                |
| prompt toolkit   | 2.0.9               |
| shell type       | prompt_toolkit2     |
| pygments         | 2.4.2               |
| on posix         | True                |
| on linux         | True                |
| distro           | fedora              |
| on darwin        | False               |
| on windows       | False               |
| on cygwin        | False               |
| on msys2         | False               |
| is superuser     | False               |
| default encoding | utf-8               |
| xonsh encoding   | utf-8               |
| encoding errors  | surrogateescape     |
+------------------+---------------------+
```

## Expected Behavior
When defining a function, eg:
```
def some_func(some_arg):
    print(some_arg)
```
Should just define the function with no errors and I should be able to call said function at will

## Current Behavior
Crashes on noted error

### Traceback (if applicable)

```
..........

def some_func(some_arg):
    print(some_arg)
    
..........

<_ast.Interactive object at 0x7fa0d29a5790>
<class '_ast.Interactive'>
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_attributes', '_fields', 'body']
xonsh: To log full traceback to a file set: $XONSH_TRACEBACK_LOGFILE = <filename>
Traceback (most recent call last):
  File "/home/mock/rpmbuild/BUILDROOT/xonsh-0.9.10-1.fc31.x86_64/usr/lib/python3.8/site-packages/xonsh/ptk2/shell.py", line 178, in _push
    code = self.execer.compile(src, mode="single", glbs=self.ctx, locs=None)
  File "/home/mock/rpmbuild/BUILDROOT/xonsh-0.9.10-1.fc31.x86_64/usr/lib/python3.8/site-packages/xonsh/__amalgam__.py", line 23101, in compile
    code = compile(tree, filename, mode)
TypeError: required field "posonlyargs" missing from arguments
```

## Steps to Reproduce
Run xonsh with python 3.8
define a function
failure


Discussion:
Hey @jhdulaney -- thanks for reporting!

I can't reproduce this on OSX.  Which Python 3.8 are you using?  I'm on 3.8.0a3 in this environment:

```
(py38) gil ~/githu/xonsh/xonsh master $ xonfig
+------------------+---------------------+
| xonsh            | 0.9.10              |
| Git SHA          | aae977c4            |
| Commit Date      | Aug 6 12:40:51 2019 |
| Python           | 3.8.0               |
| PLY              | 3.11                |
| have readline    | True                |
| prompt toolkit   | 2.0.9               |
| shell type       | prompt_toolkit2     |
| pygments         | None                |
| on posix         | True                |
| on linux         | False               |
| on darwin        | True                |
| on windows       | False               |
| on cygwin        | False               |
| on msys2         | False               |
| is superuser     | False               |
| default encoding | utf-8               |
| xonsh encoding   | utf-8               |
| encoding errors  | surrogateescape     |
+------------------+---------------------+
(py38) gil ~/githu/xonsh/xonsh master $ def func(some_arg):
.......................................     print(some_arg)
.......................................
(py38) gil ~/githu/xonsh/xonsh master $ func('hi')
hi
(py38) gil ~/githu/xonsh/xonsh master $ python --version
Python 3.8.0a3
```
3.8.0b3 on Linux
 I got it figured out, will try and have a pull request shortly.
Excellent! I look forward to the PR @jhdulaney!
I have the same error while running the tests during the building of the RPM for Fedora 32:

```
/builddir/build/BUILDROOT/xonsh-0.9.10-3.fc32.x86_64/usr/bin/xonsh run-tests.xsh
Traceback (most recent call last):
  File "/builddir/build/BUILDROOT/xonsh-0.9.10-3.fc32.x86_64/usr/bin/xonsh", line 4, in <module>
    main()
  File "/builddir/build/BUILDROOT/xonsh-0.9.10-3.fc32.x86_64/usr/lib/python3.8/site-packages/xonsh/__amalgam__.py", line 24011, in main
    _failback_to_other_shells(args, err)
  File "/builddir/build/BUILDROOT/xonsh-0.9.10-3.fc32.x86_64/usr/lib/python3.8/site-packages/xonsh/__amalgam__.py", line 23975, in _failback_to_other_shells
    raise err
  File "/builddir/build/BUILDROOT/xonsh-0.9.10-3.fc32.x86_64/usr/lib/python3.8/site-packages/xonsh/__amalgam__.py", line 24009, in main
    return main_xonsh(args)
  File "/builddir/build/BUILDROOT/xonsh-0.9.10-3.fc32.x86_64/usr/lib/python3.8/site-packages/xonsh/__amalgam__.py", line 24052, in main_xonsh
    run_script_with_cache(
  File "/builddir/build/BUILDROOT/xonsh-0.9.10-3.fc32.x86_64/usr/lib/python3.8/site-packages/xonsh/__amalgam__.py", line 3036, in run_script_with_cache
    ccode = compile_code(filename, code, execer, glb, loc, mode)
  File "/builddir/build/BUILDROOT/xonsh-0.9.10-3.fc32.x86_64/usr/lib/python3.8/site-packages/xonsh/__amalgam__.py", line 2995, in compile_code
    ccode = execer.compile(code, glbs=glb, locs=loc, mode=mode, filename=filename)
  File "/builddir/build/BUILDROOT/xonsh-0.9.10-3.fc32.x86_64/usr/lib/python3.8/site-packages/xonsh/__amalgam__.py", line 23095, in compile
    code = compile(tree, filename, mode)
TypeError: required field "posonlyargs" missing from arguments
error: Bad exit status from /var/tmp/rpm-tmp.TyaM7t (%check)
    Bad exit status from /var/tmp/rpm-tmp.TyaM7t (%check)
```

Resolving patch:
diff --git a/xonsh/parsers/base.py b/xonsh/parsers/base.py
--- a/xonsh/parsers/base.py
+++ b/xonsh/parsers/base.py
@@ -853,6 +853,7 @@ def p_parameters(self, p):
         p2 = p[2]
         if p2 is None:
             p2 = ast.arguments(
+                posonlyargs=[],
                 args=[],
                 vararg=None,
                 kwonlyargs=[],
@@ -869,14 +870,26 @@ def p_equals_test(self, p):
     def p_typedargslist_kwarg(self, p):
         """typedargslist : POW tfpdef"""
         p[0] = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[2], defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=p[2],
+            defaults=[],
         )
 
     def p_typedargslist_times4_tfpdef(self, p):
         """typedargslist : TIMES tfpdef comma_pow_tfpdef_opt"""
         # *args, **kwargs
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[3], defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=p[3],
+            defaults=[],
         )
         self._set_var_args(p0, p[2], None)
         p[0] = p0
@@ -885,7 +898,13 @@ def p_typedargslist_times4_comma(self, p):
         """typedargslist : TIMES comma_pow_tfpdef"""
         # *, **kwargs
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[2], defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=p[2],
+            defaults=[],
         )
         p[0] = p0
 
@@ -893,7 +912,13 @@ def p_typedargslist_times5_tdpdef(self, p):
         """typedargslist : TIMES tfpdef comma_tfpdef_list comma_pow_tfpdef_opt"""
         # *args, x, **kwargs
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[4], defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=p[4],
+            defaults=[],
         )
         self._set_var_args(p0, p[2], p[3])  # *args
         p[0] = p0
@@ -902,7 +927,13 @@ def p_typedargslist_times5_comma(self, p):
         """typedargslist : TIMES comma_tfpdef_list comma_pow_tfpdef_opt"""
         # *, x, **kwargs
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[3], defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=p[3],
+            defaults=[],
         )
         self._set_var_args(p0, None, p[2])  # *args
         p[0] = p0
@@ -911,7 +942,13 @@ def p_typedargslist_t5(self, p):
         """typedargslist : tfpdef equals_test_opt comma_tfpdef_list_opt comma_opt"""
         # x
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=None,
+            defaults=[],
         )
         self._set_regular_args(p0, p[1], p[2], p[3], p[4])
         p[0] = p0
@@ -920,7 +957,13 @@ def p_typedargslist_t7(self, p):
         """typedargslist : tfpdef equals_test_opt comma_tfpdef_list_opt comma_opt POW tfpdef"""
         # x, **kwargs
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[6], defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=p[6],
+            defaults=[],
         )
         self._set_regular_args(p0, p[1], p[2], p[3], p[4])
         p[0] = p0
@@ -928,7 +971,13 @@ def p_typedargslist_t7(self, p):
     def p_typedargslist_t8(self, p):
         """typedargslist : tfpdef equals_test_opt comma_tfpdef_list_opt comma_opt TIMES tfpdef_opt comma_tfpdef_list_opt"""
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=None,
+            defaults=[],
         )
         self._set_regular_args(p0, p[1], p[2], p[3], p[4])
         self._set_var_args(p0, p[6], p[7])
@@ -938,7 +987,13 @@ def p_typedargslist_t10(self, p):
         """typedargslist : tfpdef equals_test_opt comma_tfpdef_list_opt comma_opt TIMES tfpdef_opt COMMA POW vfpdef"""
         # x, *args, **kwargs
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[9], defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=p[9],
+            defaults=[],
         )
         self._set_regular_args(p0, p[1], p[2], p[3], p[4])
         self._set_var_args(p0, p[6], None)
@@ -948,6 +1003,7 @@ def p_typedargslist_t11(self, p):
         """typedargslist : tfpdef equals_test_opt comma_tfpdef_list_opt comma_opt TIMES tfpdef_opt comma_tfpdef_list COMMA POW tfpdef"""
         # x, *args, **kwargs
         p0 = ast.arguments(
+            posonlyargs=[],
             args=[],
             vararg=None,
             kwonlyargs=[],
@@ -1033,13 +1089,25 @@ def _set_var_args(self, p0, vararg, kwargs):
     def p_varargslist_kwargs(self, p):
         """varargslist : POW vfpdef"""
         p[0] = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[2], defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=p[2],
+            defaults=[],
         )
 
     def p_varargslist_times4(self, p):
         """varargslist : TIMES vfpdef_opt comma_pow_vfpdef_opt"""
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[3], defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=p[3],
+            defaults=[],
         )
         self._set_var_args(p0, p[2], None)
         p[0] = p0
@@ -1048,7 +1116,13 @@ def p_varargslist_times5(self, p):
         """varargslist : TIMES vfpdef_opt comma_vfpdef_list comma_pow_vfpdef_opt"""
         # *args, x, **kwargs
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[4], defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=p[4],
+            defaults=[],
         )
         self._set_var_args(p0, p[2], p[3])  # *args
         p[0] = p0
@@ -1057,7 +1131,13 @@ def p_varargslist_v5(self, p):
         """varargslist : vfpdef equals_test_opt comma_vfpdef_list_opt comma_opt"""
         # x
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=None,
+            defaults=[],
         )
         self._set_regular_args(p0, p[1], p[2], p[3], p[4])
         p[0] = p0
@@ -1066,7 +1146,13 @@ def p_varargslist_v7(self, p):
         """varargslist : vfpdef equals_test_opt comma_vfpdef_list_opt comma_opt POW vfpdef"""
         # x, **kwargs
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[6], defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=p[6],
+            defaults=[],
         )
         self._set_regular_args(p0, p[1], p[2], p[3], p[4])
         p[0] = p0
@@ -1075,7 +1161,13 @@ def p_varargslist_v8(self, p):
         """varargslist : vfpdef equals_test_opt comma_vfpdef_list_opt comma_opt TIMES vfpdef_opt comma_vfpdef_list_opt"""
         # x, *args
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=None,
+            defaults=[],
         )
         self._set_regular_args(p0, p[1], p[2], p[3], p[4])
         self._set_var_args(p0, p[6], p[7])
@@ -1085,7 +1177,13 @@ def p_varargslist_v10(self, p):
         """varargslist : vfpdef equals_test_opt comma_vfpdef_list_opt comma_opt TIMES vfpdef_opt COMMA POW vfpdef"""
         # x, *args, **kwargs
         p0 = ast.arguments(
-            args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=p[9], defaults=[]
+            posonlyargs=[],
+            args=[],
+            vararg=None,
+            kwonlyargs=[],
+            kw_defaults=[],
+            kwarg=p[9],
+            defaults=[],
         )
         self._set_regular_args(p0, p[1], p[2], p[3], p[4])
         self._set_var_args(p0, p[6], None)
@@ -1094,6 +1192,7 @@ def p_varargslist_v10(self, p):
     def p_varargslist_v11(self, p):
         """varargslist : vfpdef equals_test_opt comma_vfpdef_list_opt comma_opt TIMES vfpdef_opt comma_vfpdef_list COMMA POW vfpdef"""
         p0 = ast.arguments(
+            posonlyargs=[],
             args=[],
             vararg=None,
             kwonlyargs=[],
@@ -1858,6 +1957,7 @@ def p_lambdef(self, p):
         p1, p2, p4 = p[1], p[2], p[4]
         if p2 is None:
             args = ast.arguments(
+                posonlyargs=[],
                 args=[],
                 vararg=None,
                 kwonlyargs=[],


Test patch: