##// END OF EJS Templates
extensions: address ast deprecations introduced in Python 3.12...
Mads Kiilerich -
r51648:b9eb65a1 stable
parent child Browse files
Show More
@@ -885,16 +885,31 b' def _disabledcmdtable(path):'
885 885 with open(path, b'rb') as src:
886 886 root = ast.parse(src.read(), path)
887 887 cmdtable = {}
888
889 # Python 3.12 started removing Bytes and Str and deprecate harder
890 use_constant = 'Bytes' not in vars(ast)
891
888 892 for node in _walkcommand(root):
889 893 if not node.args:
890 894 continue
891 895 a = node.args[0]
892 if isinstance(a, ast.Str):
893 name = pycompat.sysbytes(a.s)
894 elif isinstance(a, ast.Bytes):
895 name = a.s
896 else:
897 continue
896 if use_constant: # Valid since Python 3.8
897 if isinstance(a, ast.Constant):
898 if isinstance(a.value, str):
899 name = pycompat.sysbytes(a.value)
900 elif isinstance(a.value, bytes):
901 name = a.value
902 else:
903 continue
904 else:
905 continue
906 else: # Valid until 3.11
907 if isinstance(a, ast.Str):
908 name = pycompat.sysbytes(a.s)
909 elif isinstance(a, ast.Bytes):
910 name = a.s
911 else:
912 continue
898 913 cmdtable[name] = (None, [], b'')
899 914 return cmdtable
900 915
General Comments 0
You need to be logged in to leave comments. Login now