forked from python/typeshed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more overloads to the
re
stubs to help out pyright (python#9592)
- Loading branch information
1 parent
a12c0d9
commit 50bd0df
Showing
3 changed files
with
51 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
import mmap | ||
import re | ||
import typing as t | ||
from typing_extensions import assert_type | ||
|
||
|
||
def check_search(str_pat: re.Pattern[str], bytes_pat: re.Pattern[bytes]) -> None: | ||
assert_type(str_pat.search("x"), t.Optional[t.Match[str]]) | ||
assert_type(bytes_pat.search(b"x"), t.Optional[t.Match[bytes]]) | ||
assert_type(bytes_pat.search(bytearray(b"x")), t.Optional[t.Match[bytes]]) | ||
assert_type(bytes_pat.search(mmap.mmap(0, 10)), t.Optional[t.Match[bytes]]) | ||
|
||
|
||
def check_search_with_AnyStr(pattern: re.Pattern[t.AnyStr], string: t.AnyStr) -> re.Match[t.AnyStr]: | ||
"""See issue #9591""" | ||
match = pattern.search(string) | ||
if match is None: | ||
raise ValueError(f"'{string!r}' does not match {pattern!r}") | ||
return match | ||
|
||
|
||
def check_no_ReadableBuffer_false_negatives() -> None: | ||
re.compile("foo").search(bytearray(b"foo")) # type: ignore | ||
re.compile("foo").search(mmap.mmap(0, 10)) # type: ignore |
This file was deleted.
Oops, something went wrong.