mercurial/pycompat.py
changeset 50101 b900f40c343e
parent 49807 c5a06cc37401
child 50175 0ab92dabea6e
equal deleted inserted replaced
50099:0f0880c8a7e5 50101:b900f40c343e
   242             s, u'__bytes__'
   242             s, u'__bytes__'
   243         ):
   243         ):
   244             s = str(s).encode('ascii')
   244             s = str(s).encode('ascii')
   245         return bytes.__new__(cls, s)
   245         return bytes.__new__(cls, s)
   246 
   246 
   247     def __getitem__(self, key) -> bytes:
   247     # The base class uses `int` return in py3, but the point of this class is to
       
   248     # behave like py2.
       
   249     def __getitem__(self, key) -> bytes:  # pytype: disable=signature-mismatch
   248         s = bytes.__getitem__(self, key)
   250         s = bytes.__getitem__(self, key)
   249         if not isinstance(s, bytes):
   251         if not isinstance(s, bytes):
   250             s = bytechr(s)
   252             s = bytechr(s)
   251         return s
   253         return s
   252 
   254 
   253     def __iter__(self) -> Iterator[bytes]:
   255     # The base class expects `Iterator[int]` return in py3, but the point of
       
   256     # this class is to behave like py2.
       
   257     def __iter__(self) -> Iterator[bytes]:  # pytype: disable=signature-mismatch
   254         return iterbytestr(bytes.__iter__(self))
   258         return iterbytestr(bytes.__iter__(self))
   255 
   259 
   256     def __repr__(self) -> str:
   260     def __repr__(self) -> str:
   257         return bytes.__repr__(self)[1:]  # drop b''
   261         return bytes.__repr__(self)[1:]  # drop b''
   258 
   262