@@ -147,7 +147,7 @@ def is_bool(node): |
147 | 147 | @staticmethod |
148 | 148 | def is_number(node): |
149 | 149 | """Check if the node is a number.""" |
150 | | - return (isinstance(node, ast.Num) or |
| 150 | + return ((isinstance(node, ast.Constant) and isinstance(node.value, int)) or |
151 | 151 | (isinstance(node, ast.UnaryOp) and |
152 | 152 | isinstance(node.op, (ast.UAdd, ast.USub)))) |
153 | 153 |
|
@@ -201,7 +201,7 @@ def _ast_compare(self, node): |
201 | 201 |
|
202 | 202 | def _ast_constant(self, node): |
203 | 203 | """Add an AST Constant in output.""" |
204 | | - self.add(repr(node.s)) |
| 204 | + self.add(repr(node.value)) |
205 | 205 |
|
206 | 206 | def _ast_dict(self, node): |
207 | 207 | """Add an AST Dict in output.""" |
@@ -214,7 +214,7 @@ def _ast_dict(self, node): |
214 | 214 |
|
215 | 215 | def _ast_expr(self, node): |
216 | 216 | """Add an AST Expr in output.""" |
217 | | - if not isinstance(node.value, ast.Str): # ignore docstrings |
| 217 | + if not isinstance(node.value, ast.Constant): # ignore docstrings |
218 | 218 | self.add( |
219 | 219 | self.fill, |
220 | 220 | node.value, |
@@ -283,7 +283,6 @@ def _ast_name(self, node): |
283 | 283 |
|
284 | 284 | def _ast_num(self, node): |
285 | 285 | """Add an AST Num in output.""" |
286 | | - # note: deprecated since Python 3.8, replaced by ast.Constant |
287 | 286 | self.add(repr(node.n)) |
288 | 287 |
|
289 | 288 | def _ast_pass(self, node): # pylint: disable=unused-argument |
@@ -298,7 +297,6 @@ def _ast_return(self, node): |
298 | 297 |
|
299 | 298 | def _ast_str(self, node): |
300 | 299 | """Add an AST Str in output.""" |
301 | | - # note: deprecated since Python 3.8, replaced by ast.Constant |
302 | 300 | self._ast_constant(node) |
303 | 301 |
|
304 | 302 | def _ast_subscript(self, node): |
@@ -405,11 +403,11 @@ def _ast_compare(self, node): |
405 | 403 | def _ast_constant(self, node): |
406 | 404 | """Add an AST Constant in output.""" |
407 | 405 | if isinstance(node.value, str): |
408 | | - self.add('"%s"' % node.s.replace('$', '\\$').replace('@', '\\@')) |
| 406 | + self.add('"%s"' % node.value.replace('$', '\\$').replace('@', '\\@')) |
409 | 407 | elif node.value is None: |
410 | 408 | self.add('undef') |
411 | 409 | else: |
412 | | - self.add(repr(node.s)) |
| 410 | + self.add(repr(node.value)) |
413 | 411 |
|
414 | 412 | def _ast_dict(self, node): |
415 | 413 | """Add an AST Dict in output.""" |
@@ -422,7 +420,7 @@ def _ast_dict(self, node): |
422 | 420 |
|
423 | 421 | def _ast_expr(self, node): |
424 | 422 | """Add an AST Expr in output.""" |
425 | | - if not isinstance(node.value, ast.Str): # ignore docstrings |
| 423 | + if not isinstance(node.value, ast.Constant): # ignore docstrings |
426 | 424 | self.add( |
427 | 425 | self.fill, |
428 | 426 | node.value, |
@@ -512,8 +510,7 @@ def _ast_return(self, node): |
512 | 510 |
|
513 | 511 | def _ast_str(self, node): |
514 | 512 | """Add an AST Str in output.""" |
515 | | - # note: deprecated since Python 3.8, replaced by ast.Constant |
516 | | - self.add('"%s"' % node.s.replace('$', '\\$').replace('@', '\\@')) |
| 513 | + self._ast_constant(node) |
517 | 514 |
|
518 | 515 | def _ast_subscript(self, node): |
519 | 516 | """Add an AST Subscript in output.""" |
@@ -548,11 +545,11 @@ def _ast_attribute(self, node): |
548 | 545 | def _ast_constant(self, node): |
549 | 546 | """Add an AST Constant in output.""" |
550 | 547 | if isinstance(node.value, str): |
551 | | - self.add('"%s"' % node.s.replace('#{', '\\#{')) |
| 548 | + self.add('"%s"' % node.value.replace('#{', '\\#{')) |
552 | 549 | elif node.value is None: |
553 | 550 | self.add('nil') |
554 | 551 | else: |
555 | | - self.add(repr(node.s)) |
| 552 | + self.add(repr(node.value)) |
556 | 553 |
|
557 | 554 | def _ast_dict(self, node): |
558 | 555 | """Add an AST Dict in output.""" |
@@ -619,8 +616,7 @@ def _ast_pass(self, node): |
619 | 616 |
|
620 | 617 | def _ast_str(self, node): |
621 | 618 | """Add an AST Str in output.""" |
622 | | - # note: deprecated since Python 3.8, replaced by ast.Constant |
623 | | - self.add('"%s"' % node.s) |
| 619 | + self._ast_constant(node) |
624 | 620 |
|
625 | 621 |
|
626 | 622 | class UnparseLua(UnparsePython): |
@@ -663,7 +659,7 @@ def _ast_constant(self, node): |
663 | 659 | if node.value is None: |
664 | 660 | self.add('nil') |
665 | 661 | else: |
666 | | - self.add(repr(node.s)) |
| 662 | + self.add(repr(node.value)) |
667 | 663 |
|
668 | 664 | def _ast_dict(self, node): |
669 | 665 | """Add an AST Dict in output.""" |
@@ -744,7 +740,7 @@ def __init__(self, *args, **kwargs): |
744 | 740 |
|
745 | 741 | def _ast_assign(self, node): |
746 | 742 | """Add an AST Assign in output.""" |
747 | | - exclude_types = (ast.Dict, ast.List, ast.Str, ast.Subscript) |
| 743 | + exclude_types = (ast.Dict, ast.List, ast.Constant, ast.Subscript) |
748 | 744 | self.add( |
749 | 745 | self.fill, |
750 | 746 | 'set ', |
@@ -821,11 +817,11 @@ def _ast_compare(self, node): |
821 | 817 | def _ast_constant(self, node): |
822 | 818 | """Add an AST Constant in output.""" |
823 | 819 | if isinstance(node.value, str): |
824 | | - self.add('"%s"' % node.s.replace('$', '\\$')) |
| 820 | + self.add('"%s"' % node.value.replace('$', '\\$')) |
825 | 821 | elif node.value is None: |
826 | 822 | self.add('$::weechat::WEECHAT_NULL') |
827 | 823 | else: |
828 | | - self.add(repr(node.s)) |
| 824 | + self.add(repr(node.value)) |
829 | 825 |
|
830 | 826 | def _ast_dict(self, node): |
831 | 827 | """Add an AST Dict in output.""" |
@@ -903,8 +899,7 @@ def _ast_return(self, node): |
903 | 899 |
|
904 | 900 | def _ast_str(self, node): |
905 | 901 | """Add an AST Str in output.""" |
906 | | - # note: deprecated since Python 3.8, replaced by ast.Constant |
907 | | - self.add('"%s"' % node.s.replace('$', '\\$')) |
| 902 | + self._ast_constant(node) |
908 | 903 |
|
909 | 904 | def _ast_subscript(self, node): |
910 | 905 | """Add an AST Subscript in output.""" |
@@ -965,8 +960,8 @@ def _ast_attribute(self, node): |
965 | 960 | def _ast_binop(self, node): |
966 | 961 | """Add an AST BinOp in output.""" |
967 | 962 | if isinstance(node.op, ast.Add) and \ |
968 | | - (isinstance(node.left, (ast.Name, ast.Str)) or |
969 | | - isinstance(node.right, (ast.Name, ast.Str))): |
| 963 | + (isinstance(node.left, (ast.Name, ast.Constant)) or |
| 964 | + isinstance(node.right, (ast.Name, ast.Constant))): |
970 | 965 | self.add( |
971 | 966 | '(string-append ', |
972 | 967 | node.left, |
@@ -1014,12 +1009,12 @@ def _ast_compare(self, node): |
1014 | 1009 |
|
1015 | 1010 | def _ast_constant(self, node): |
1016 | 1011 | """Add an AST Constant in output.""" |
1017 | | - if isinstance(node.s, str): |
1018 | | - self.add('"%s"' % node.s) |
| 1012 | + if isinstance(node.value, str): |
| 1013 | + self.add('"%s"' % node.value) |
1019 | 1014 | elif node.value is None: |
1020 | 1015 | self.add('#nil') |
1021 | 1016 | else: |
1022 | | - self.add(repr(node.s)) |
| 1017 | + self.add(repr(node.value)) |
1023 | 1018 |
|
1024 | 1019 | def _ast_dict(self, node): |
1025 | 1020 | """Add an AST Dict in output.""" |
@@ -1111,8 +1106,7 @@ def _ast_return(self, node): |
1111 | 1106 |
|
1112 | 1107 | def _ast_str(self, node): |
1113 | 1108 | """Add an AST Str in output.""" |
1114 | | - # note: deprecated since Python 3.8, replaced by ast.Constant |
1115 | | - self.add('"%s"' % node.s) |
| 1109 | + self._ast_constant(node) |
1116 | 1110 |
|
1117 | 1111 | def _ast_subscript(self, node): |
1118 | 1112 | """Add an AST Subscript in output.""" |
@@ -1149,7 +1143,7 @@ def _ast_constant(self, node): |
1149 | 1143 | if node.value is None: |
1150 | 1144 | self.add('null') |
1151 | 1145 | else: |
1152 | | - self.add(repr(node.s)) |
| 1146 | + self.add(repr(node.value)) |
1153 | 1147 |
|
1154 | 1148 | def _ast_functiondef(self, node): |
1155 | 1149 | """Add an AST FunctionDef in output.""" |
@@ -1227,8 +1221,8 @@ def _ast_attribute(self, node): |
1227 | 1221 | def _ast_binop(self, node): |
1228 | 1222 | """Add an AST BinOp in output.""" |
1229 | 1223 | if isinstance(node.op, ast.Add) and \ |
1230 | | - (isinstance(node.left, (ast.Name, ast.Str)) or |
1231 | | - isinstance(node.right, (ast.Name, ast.Str))): |
| 1224 | + (isinstance(node.left, (ast.Name, ast.Constant)) or |
| 1225 | + isinstance(node.right, (ast.Name, ast.Constant))): |
1232 | 1226 | str_op = '.' |
1233 | 1227 | else: |
1234 | 1228 | str_op = self.binop[node.op.__class__.__name__] |
@@ -1253,12 +1247,12 @@ def _ast_call(self, node): |
1253 | 1247 |
|
1254 | 1248 | def _ast_constant(self, node): |
1255 | 1249 | """Add an AST Constant in output.""" |
1256 | | - if isinstance(node.s, str): |
1257 | | - self.add('"%s"' % node.s.replace('$', '\\$')) |
| 1250 | + if isinstance(node.value, str): |
| 1251 | + self.add('"%s"' % node.value.replace('$', '\\$')) |
1258 | 1252 | elif node.value is None: |
1259 | 1253 | self.add('NULL') |
1260 | 1254 | else: |
1261 | | - self.add(repr(node.s)) |
| 1255 | + self.add(repr(node.value)) |
1262 | 1256 |
|
1263 | 1257 | def _ast_dict(self, node): |
1264 | 1258 | """Add an AST Dict in output.""" |
@@ -1271,7 +1265,7 @@ def _ast_dict(self, node): |
1271 | 1265 |
|
1272 | 1266 | def _ast_expr(self, node): |
1273 | 1267 | """Add an AST Expr in output.""" |
1274 | | - if not isinstance(node.value, ast.Str): # ignore docstrings |
| 1268 | + if not isinstance(node.value, ast.Constant): # ignore docstrings |
1275 | 1269 | self.add( |
1276 | 1270 | self.fill, |
1277 | 1271 | node.value, |
@@ -1353,8 +1347,7 @@ def _ast_return(self, node): |
1353 | 1347 |
|
1354 | 1348 | def _ast_str(self, node): |
1355 | 1349 | """Add an AST Str in output.""" |
1356 | | - # note: deprecated since Python 3.8, replaced by ast.Constant |
1357 | | - self.add('"%s"' % node.s.replace('$', '\\$')) |
| 1350 | + self._ast_constant(node) |
1358 | 1351 |
|
1359 | 1352 | def _ast_subscript(self, node): |
1360 | 1353 | """Add an AST Subscript in output.""" |
|