@@ -573,6 +573,7 @@ static PyObject* ast2obj_object(void *o)
573573}
574574#define ast2obj_identifier ast2obj_object
575575#define ast2obj_string ast2obj_object
576+ #define ast2obj_bytes ast2obj_object
576577
577578static PyObject * ast2obj_int (long b )
578579{
@@ -610,6 +611,15 @@ static int obj2ast_string(PyObject* obj, PyObject** out, PyArena* arena)
610611 return obj2ast_object (obj , out , arena );
611612}
612613
614+ static int obj2ast_bytes (PyObject * obj , PyObject * * out , PyArena * arena )
615+ {
616+ if (!PyBytes_CheckExact (obj )) {
617+ PyErr_SetString (PyExc_TypeError , "AST bytes must be of type bytes" );
618+ return 1 ;
619+ }
620+ return obj2ast_object (obj , out , arena );
621+ }
622+
613623static int obj2ast_int (PyObject * obj , int * out , PyArena * arena )
614624{
615625 int i ;
@@ -1773,7 +1783,7 @@ Str(string s, int lineno, int col_offset, PyArena *arena)
17731783}
17741784
17751785expr_ty
1776- Bytes (string s , int lineno , int col_offset , PyArena * arena )
1786+ Bytes (bytes s , int lineno , int col_offset , PyArena * arena )
17771787{
17781788 expr_ty p ;
17791789 if (!s ) {
@@ -2804,7 +2814,7 @@ ast2obj_expr(void* _o)
28042814 case Bytes_kind :
28052815 result = PyType_GenericNew (Bytes_type , NULL , NULL );
28062816 if (!result ) goto failed ;
2807- value = ast2obj_string (o -> v .Bytes .s );
2817+ value = ast2obj_bytes (o -> v .Bytes .s );
28082818 if (!value ) goto failed ;
28092819 if (PyObject_SetAttrString (result , "s" , value ) == -1 )
28102820 goto failed ;
@@ -5509,13 +5519,13 @@ obj2ast_expr(PyObject* obj, expr_ty* out, PyArena* arena)
55095519 return 1 ;
55105520 }
55115521 if (isinstance ) {
5512- string s ;
5522+ bytes s ;
55135523
55145524 if (PyObject_HasAttrString (obj , "s" )) {
55155525 int res ;
55165526 tmp = PyObject_GetAttrString (obj , "s" );
55175527 if (tmp == NULL ) goto failed ;
5518- res = obj2ast_string (tmp , & s , arena );
5528+ res = obj2ast_bytes (tmp , & s , arena );
55195529 if (res != 0 ) goto failed ;
55205530 Py_XDECREF (tmp );
55215531 tmp = NULL ;
0 commit comments