Skip to content

Commit f192b8c

Browse files
5j9gvanrossum
authored andcommitted
Update count, (r)find, and (r)index type hints for bytes and bytearray (#923)
The above methods have changed in version 3.3 to also accept an integer in the range 0 to 255 as the subsequence. Fixes python/mypy#2831
1 parent 65b4528 commit f192b8c

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

stdlib/3/builtins.pyi

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,23 @@ class bytes(ByteString):
299299
def __init__(self, o: SupportsBytes) -> None: ...
300300
def capitalize(self) -> bytes: ...
301301
def center(self, width: int, fillchar: bytes = ...) -> bytes: ...
302-
def count(self, x: bytes) -> int: ...
302+
if sys.version_info >= (3, 3):
303+
def count(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ...
304+
else:
305+
def count(self, sub: bytes, start: int = None, end: int = None) -> int: ...
303306
def decode(self, encoding: str = 'utf-8', errors: str = 'strict') -> str: ...
304307
def endswith(self, suffix: Union[bytes, Tuple[bytes, ...]]) -> bool: ...
305308
def expandtabs(self, tabsize: int = 8) -> bytes: ...
306-
def find(self, sub: bytes, start: int = 0, end: int = 0) -> int: ...
309+
if sys.version_info >= (3, 3):
310+
def find(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ...
311+
else:
312+
def find(self, sub: bytes, start: int = None, end: int = None) -> int: ...
307313
if sys.version_info >= (3, 5):
308314
def hex(self) -> str: ...
309-
def index(self, sub: bytes, start: int = 0, end: int = 0) -> int: ...
315+
if sys.version_info >= (3, 3):
316+
def index(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ...
317+
else:
318+
def index(self, sub: bytes, start: int = None, end: int = None) -> int: ...
310319
def isalnum(self) -> bool: ...
311320
def isalpha(self) -> bool: ...
312321
def isdigit(self) -> bool: ...
@@ -320,8 +329,14 @@ class bytes(ByteString):
320329
def lstrip(self, chars: bytes = None) -> bytes: ...
321330
def partition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ...
322331
def replace(self, old: bytes, new: bytes, count: int = -1) -> bytes: ...
323-
def rfind(self, sub: bytes, start: int = 0, end: int = 0) -> int: ...
324-
def rindex(self, sub: bytes, start: int = 0, end: int = 0) -> int: ...
332+
if sys.version_info >= (3, 3):
333+
def rfind(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ...
334+
else:
335+
def rfind(self, sub: bytes, start: int = None, end: int = None) -> int: ...
336+
if sys.version_info >= (3, 3):
337+
def rindex(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ...
338+
else:
339+
def rindex(self, sub: bytes, start: int = None, end: int = None) -> int: ...
325340
def rjust(self, width: int, fillchar: bytes = ...) -> bytes: ...
326341
def rpartition(self, sep: bytes) -> Tuple[bytes, bytes, bytes]: ...
327342
def rsplit(self, sep: bytes = None, maxsplit: int = -1) -> List[bytes]: ...
@@ -373,14 +388,23 @@ class bytearray(MutableSequence[int], ByteString):
373388
def __init__(self) -> None: ...
374389
def capitalize(self) -> bytearray: ...
375390
def center(self, width: int, fillchar: bytes = ...) -> bytearray: ...
376-
def count(self, x: bytes) -> int: ...
391+
if sys.version_info >= (3, 3):
392+
def count(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ...
393+
else:
394+
def count(self, sub: bytes, start: int = None, end: int = None) -> int: ...
377395
def decode(self, encoding: str = 'utf-8', errors: str = 'strict') -> str: ...
378396
def endswith(self, suffix: bytes) -> bool: ...
379397
def expandtabs(self, tabsize: int = 8) -> bytearray: ...
380-
def find(self, sub: bytes, start: int = 0, end: int = 0) -> int: ...
398+
if sys.version_info >= (3, 3):
399+
def find(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ...
400+
else:
401+
def find(self, sub: bytes, start: int = None, end: int = None) -> int: ...
381402
if sys.version_info >= (3, 5):
382403
def hex(self) -> str: ...
383-
def index(self, sub: bytes, start: int = 0, end: int = 0) -> int: ...
404+
if sys.version_info >= (3, 3):
405+
def index(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ...
406+
else:
407+
def index(self, sub: bytes, start: int = None, end: int = None) -> int: ...
384408
def insert(self, index: int, object: int) -> None: ...
385409
def isalnum(self) -> bool: ...
386410
def isalpha(self) -> bool: ...
@@ -395,8 +419,14 @@ class bytearray(MutableSequence[int], ByteString):
395419
def lstrip(self, chars: bytes = None) -> bytearray: ...
396420
def partition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ...
397421
def replace(self, old: bytes, new: bytes, count: int = -1) -> bytearray: ...
398-
def rfind(self, sub: bytes, start: int = 0, end: int = 0) -> int: ...
399-
def rindex(self, sub: bytes, start: int = 0, end: int = 0) -> int: ...
422+
if sys.version_info >= (3, 3):
423+
def rfind(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ...
424+
else:
425+
def rfind(self, sub: bytes, start: int = None, end: int = None) -> int: ...
426+
if sys.version_info >= (3, 3):
427+
def rindex(self, sub: Union[bytes, int], start: int = None, end: int = None) -> int: ...
428+
else:
429+
def rindex(self, sub: bytes, start: int = None, end: int = None) -> int: ...
400430
def rjust(self, width: int, fillchar: bytes = ...) -> bytearray: ...
401431
def rpartition(self, sep: bytes) -> Tuple[bytearray, bytearray, bytearray]: ...
402432
def rsplit(self, sep: bytes = None, maxsplit: int = -1) -> List[bytearray]: ...

0 commit comments

Comments
 (0)