|
22 | 22 | """ |
23 | 23 | from _ast import * |
24 | 24 |
|
25 | | - |
26 | 25 | def parse(source, filename='<unknown>', mode='exec', *, |
27 | 26 | type_comments=False, feature_version=None, optimize=-1): |
28 | 27 | """ |
@@ -607,9 +606,13 @@ def __new__(cls, dims=(), **kwargs): |
607 | 606 |
|
608 | 607 | def _dims_getter(self): |
609 | 608 | """Deprecated. Use elts instead.""" |
| 609 | + import warnings |
| 610 | + warnings._deprecated(f"ast.Tuple.dims", remove=(3, 20)) |
610 | 611 | return self.elts |
611 | 612 |
|
612 | 613 | def _dims_setter(self, value): |
| 614 | + import warnings |
| 615 | + warnings._deprecated(f"ast.Tuple.dims", remove=(3, 20)) |
613 | 616 | self.elts = value |
614 | 617 |
|
615 | 618 | Tuple.dims = property(_dims_getter, _dims_setter) |
@@ -689,5 +692,23 @@ def main(args=None): |
689 | 692 | print(dump(tree, include_attributes=args.include_attributes, |
690 | 693 | indent=args.indent, show_empty=args.show_empty)) |
691 | 694 |
|
| 695 | +_deprecated = { |
| 696 | + 'slice': globals().pop("slice"), |
| 697 | + 'Index': globals().pop("Index"), |
| 698 | + 'ExtSlice': globals().pop("ExtSlice"), |
| 699 | + 'Suite': globals().pop("Suite"), |
| 700 | + 'AugLoad': globals().pop("AugLoad"), |
| 701 | + 'AugStore': globals().pop("AugStore"), |
| 702 | + 'Param': globals().pop("Param") |
| 703 | +} |
| 704 | + |
| 705 | +def __getattr__(attr): |
| 706 | + if val := _deprecated.get(attr, None): |
| 707 | + import warnings |
| 708 | + warnings._deprecated(f"ast.{attr}", remove=(3, 20)) |
| 709 | + globals()[attr] = val |
| 710 | + return val |
| 711 | + raise AttributeError(f"module 'ast' has no attribute {attr!r}") |
| 712 | + |
692 | 713 | if __name__ == '__main__': |
693 | 714 | main() |
0 commit comments