mercurial/extensions.py
branchstable
changeset 50755 b9eb65a1ec14
parent 49777 f4a363b25859
child 50757 19108906abaf
equal deleted inserted replaced
50754:f173c2c23289 50755:b9eb65a1ec14
   883     This may raise IOError or SyntaxError.
   883     This may raise IOError or SyntaxError.
   884     """
   884     """
   885     with open(path, b'rb') as src:
   885     with open(path, b'rb') as src:
   886         root = ast.parse(src.read(), path)
   886         root = ast.parse(src.read(), path)
   887     cmdtable = {}
   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     for node in _walkcommand(root):
   892     for node in _walkcommand(root):
   889         if not node.args:
   893         if not node.args:
   890             continue
   894             continue
   891         a = node.args[0]
   895         a = node.args[0]
   892         if isinstance(a, ast.Str):
   896         if use_constant:  # Valid since Python 3.8
   893             name = pycompat.sysbytes(a.s)
   897             if isinstance(a, ast.Constant):
   894         elif isinstance(a, ast.Bytes):
   898                 if isinstance(a.value, str):
   895             name = a.s
   899                     name = pycompat.sysbytes(a.value)
   896         else:
   900                 elif isinstance(a.value, bytes):
   897             continue
   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         cmdtable[name] = (None, [], b'')
   913         cmdtable[name] = (None, [], b'')
   899     return cmdtable
   914     return cmdtable
   900 
   915 
   901 
   916 
   902 def _finddisabledcmd(ui, cmd, name, path, strict):
   917 def _finddisabledcmd(ui, cmd, name, path, strict):