Skip to content

Commit 067d0a0

Browse files
committed
pyright: fix some errors
1 parent 1fd14b5 commit 067d0a0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

native/src/regex_wrapper.pyi

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import List, Optional
2+
3+
def compile_pattern(pattern: str) -> int: ...
4+
def match_compiled(id: int, text: str) -> bool: ...
5+
def release_compiled(id: int) -> None: ...
6+
def match(pattern: str, text: str) -> bool: ...
7+
def search_pattern(id: int, text: str) -> Optional[str]: ...
8+
def findall_pattern(id: int, text: str) -> List[str]: ...
9+
def free_matches(matches: List[str]) -> None: ...
10+
def substitute_pattern(id: int, text: str, replacement: str) -> Optional[str]: ...
11+
def free(ptr: object) -> None: ...

src/stdlib/re.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import cast
2+
13
import cffi
24

35
from stdlib._cffi_util import load_library
@@ -45,7 +47,7 @@ def search(self, text: str) -> str | None:
4547
if result:
4648
ptr = result
4749
try:
48-
result_bytes: bytes = ffi.string(result)
50+
result_bytes = cast(bytes, ffi.string(result))
4951
return result_bytes.decode("utf-8")
5052
finally:
5153
lib.free(ptr)
@@ -60,7 +62,9 @@ def findall(self, text: str) -> list[str]:
6062
# Convert the array of C strings to a Python list
6163
i = 0
6264
while matches_ptr[i]:
63-
matches.append(ffi.string(matches_ptr[i]).decode("utf-8"))
65+
matches.append(
66+
cast(bytes, ffi.string(matches_ptr[i])).decode("utf-8")
67+
)
6468
i += 1
6569
finally:
6670
# Free the allocated memory
@@ -75,7 +79,7 @@ def sub(self, replacement: str, text: str) -> str:
7579
if result:
7680
ptr = result
7781
try:
78-
result_bytes: bytes = ffi.string(result)
82+
result_bytes = cast(bytes, ffi.string(result))
7983
return result_bytes.decode("utf-8")
8084
finally:
8185
lib.free(ptr)

0 commit comments

Comments
 (0)